blob: 689607db55d6dfe015115d6d773bf5d3e2a838fd [file] [log] [blame]
Jeff Browna3477c82010-11-10 16:03:06 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _UI_KEYBOARD_H
18#define _UI_KEYBOARD_H
19
20#include <ui/Input.h>
21#include <utils/Errors.h>
22#include <utils/String8.h>
Jeff Brown66888372010-11-29 17:37:49 -080023#include <utils/PropertyMap.h>
Jeff Browna3477c82010-11-10 16:03:06 -080024
25namespace android {
26
27enum {
28 /* Device id of the built in keyboard. */
29 DEVICE_ID_BUILT_IN_KEYBOARD = 0,
30
31 /* Device id of a generic virtual keyboard with a full layout that can be used
32 * to synthesize key events. */
33 DEVICE_ID_VIRTUAL_KEYBOARD = -1,
34};
35
36struct KeyMapInfo {
Jeff Browna3477c82010-11-10 16:03:06 -080037 String8 keyLayoutFile;
38 String8 keyCharacterMapFile;
39 bool isDefaultKeyMap;
40
41 KeyMapInfo() : isDefaultKeyMap(false) {
42 }
Jeff Brown66888372010-11-29 17:37:49 -080043
44 bool isComplete() {
45 return !keyLayoutFile.isEmpty() && !keyCharacterMapFile.isEmpty();
46 }
Jeff Browna3477c82010-11-10 16:03:06 -080047};
48
49/**
50 * Resolves the key map to use for a particular keyboard device.
51 */
Jeff Brown66888372010-11-29 17:37:49 -080052extern status_t resolveKeyMap(const String8& deviceName,
53 const PropertyMap* deviceConfiguration, KeyMapInfo& outKeyMapInfo);
Jeff Browna3477c82010-11-10 16:03:06 -080054
55/**
56 * Sets keyboard system properties.
57 */
58extern void setKeyboardProperties(int32_t deviceId, const String8& deviceName,
59 const KeyMapInfo& keyMapInfo);
60
61/**
62 * Clears keyboard system properties.
63 */
64extern void clearKeyboardProperties(int32_t deviceId);
65
66/**
67 * Gets the key character map filename for a device using inspecting system properties
68 * and then falling back on a default key character map if necessary.
69 * Returns a NAME_NOT_FOUND if none found.
70 */
71extern status_t getKeyCharacterMapFile(int32_t deviceId, String8& outKeyCharacterMapFile);
72
73/**
74 * Gets a key code by its short form label, eg. "HOME".
75 * Returns 0 if unknown.
76 */
77extern int32_t getKeyCodeByLabel(const char* label);
78
79/**
80 * Gets a key flag by its short form label, eg. "WAKE".
81 * Returns 0 if unknown.
82 */
83extern uint32_t getKeyFlagByLabel(const char* label);
84
85/**
86 * Updates a meta state field when a key is pressed or released.
87 */
88extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
89
90} // namespace android
91
92#endif // _UI_KEYBOARD_H