• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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>
23 #include <utils/PropertyMap.h>
24 
25 namespace android {
26 
27 enum {
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 
36 class KeyLayoutMap;
37 class KeyCharacterMap;
38 
39 /**
40  * Loads the key layout map and key character map for a keyboard device.
41  */
42 class KeyMap {
43 public:
44     String8 keyLayoutFile;
45     KeyLayoutMap* keyLayoutMap;
46 
47     String8 keyCharacterMapFile;
48     KeyCharacterMap* keyCharacterMap;
49 
50     KeyMap();
51     ~KeyMap();
52 
53     status_t load(const InputDeviceIdentifier& deviceIdenfier,
54             const PropertyMap* deviceConfiguration);
55 
haveKeyLayout()56     inline bool haveKeyLayout() const {
57         return !keyLayoutFile.isEmpty();
58     }
59 
haveKeyCharacterMap()60     inline bool haveKeyCharacterMap() const {
61         return !keyCharacterMapFile.isEmpty();
62     }
63 
isComplete()64     inline bool isComplete() const {
65         return haveKeyLayout() && haveKeyCharacterMap();
66     }
67 
68 private:
69     bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
70     status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
71     status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier,
72             const String8& name);
73     String8 getPath(const InputDeviceIdentifier& deviceIdentifier,
74             const String8& name, InputDeviceConfigurationFileType type);
75 };
76 
77 /**
78  * Returns true if the keyboard is eligible for use as a built-in keyboard.
79  */
80 extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
81         const PropertyMap* deviceConfiguration, const KeyMap* keyMap);
82 
83 /**
84  * Sets keyboard system properties.
85  */
86 extern void setKeyboardProperties(int32_t deviceId, const InputDeviceIdentifier& deviceIdentifier,
87         const String8& keyLayoutFile, const String8& keyCharacterMapFile);
88 
89 /**
90  * Clears keyboard system properties.
91  */
92 extern void clearKeyboardProperties(int32_t deviceId);
93 
94 /**
95  * Gets the key character map filename for a device using inspecting system properties
96  * and then falling back on a default key character map if necessary.
97  * Returns a NAME_NOT_FOUND if none found.
98  */
99 extern status_t getKeyCharacterMapFile(int32_t deviceId, String8& outKeyCharacterMapFile);
100 
101 /**
102  * Gets a key code by its short form label, eg. "HOME".
103  * Returns 0 if unknown.
104  */
105 extern int32_t getKeyCodeByLabel(const char* label);
106 
107 /**
108  * Gets a key flag by its short form label, eg. "WAKE".
109  * Returns 0 if unknown.
110  */
111 extern uint32_t getKeyFlagByLabel(const char* label);
112 
113 /**
114  * Gets a axis by its short form label, eg. "X".
115  * Returns -1 if unknown.
116  */
117 extern int32_t getAxisByLabel(const char* label);
118 
119 /**
120  * Gets a axis label by its id.
121  * Returns NULL if unknown.
122  */
123 extern const char* getAxisLabel(int32_t axisId);
124 
125 /**
126  * Updates a meta state field when a key is pressed or released.
127  */
128 extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
129 
130 /**
131  * Returns true if a key is a meta key like ALT or CAPS_LOCK.
132  */
133 extern bool isMetaKey(int32_t keyCode);
134 
135 } // namespace android
136 
137 #endif // _UI_KEYBOARD_H
138