blob: 25b2f07cff771ec96b80d990abc355e553c3174a [file] [log] [blame]
Jeff Brown5912f952013-07-01 19:10:31 -07001/*
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 _LIBINPUT_KEYBOARD_H
18#define _LIBINPUT_KEYBOARD_H
19
20#include <input/Input.h>
21#include <input/InputDevice.h>
22#include <utils/Errors.h>
23#include <utils/String8.h>
24#include <utils/PropertyMap.h>
25
26namespace android {
27
28enum {
29 /* Device id of the built in keyboard. */
30 DEVICE_ID_BUILT_IN_KEYBOARD = 0,
31
32 /* Device id of a generic virtual keyboard with a full layout that can be used
33 * to synthesize key events. */
34 DEVICE_ID_VIRTUAL_KEYBOARD = -1,
35};
36
37class KeyLayoutMap;
38class KeyCharacterMap;
39
40/**
41 * Loads the key layout map and key character map for a keyboard device.
42 */
43class KeyMap {
44public:
45 String8 keyLayoutFile;
46 sp<KeyLayoutMap> keyLayoutMap;
47
48 String8 keyCharacterMapFile;
49 sp<KeyCharacterMap> keyCharacterMap;
50
51 KeyMap();
52 ~KeyMap();
53
54 status_t load(const InputDeviceIdentifier& deviceIdenfier,
55 const PropertyMap* deviceConfiguration);
56
57 inline bool haveKeyLayout() const {
58 return !keyLayoutFile.isEmpty();
59 }
60
61 inline bool haveKeyCharacterMap() const {
62 return !keyCharacterMapFile.isEmpty();
63 }
64
65 inline bool isComplete() const {
66 return haveKeyLayout() && haveKeyCharacterMap();
67 }
68
69private:
70 bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
71 status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
72 status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier,
73 const String8& name);
74 String8 getPath(const InputDeviceIdentifier& deviceIdentifier,
75 const String8& name, InputDeviceConfigurationFileType type);
76};
77
78/**
79 * Returns true if the keyboard is eligible for use as a built-in keyboard.
80 */
81extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
82 const PropertyMap* deviceConfiguration, const KeyMap* keyMap);
83
84/**
85 * Gets a key code by its short form label, eg. "HOME".
86 * Returns 0 if unknown.
87 */
88extern int32_t getKeyCodeByLabel(const char* label);
89
90/**
91 * Gets a key flag by its short form label, eg. "WAKE".
92 * Returns 0 if unknown.
93 */
94extern uint32_t getKeyFlagByLabel(const char* label);
95
96/**
Michael Wright74bdd2e2013-10-17 17:35:53 -070097 * Gets an axis by its short form label, eg. "X".
Jeff Brown5912f952013-07-01 19:10:31 -070098 * Returns -1 if unknown.
99 */
100extern int32_t getAxisByLabel(const char* label);
101
102/**
Michael Wright74bdd2e2013-10-17 17:35:53 -0700103 * Gets an axis label by its id.
Jeff Brown5912f952013-07-01 19:10:31 -0700104 * Returns NULL if unknown.
105 */
106extern const char* getAxisLabel(int32_t axisId);
107
108/**
Michael Wright74bdd2e2013-10-17 17:35:53 -0700109 * Gets an LED by its short form label, eg. "CAPS_LOCK".
110 * Returns -1 if unknown.
111 */
112extern int32_t getLedByLabel(const char* label);
113
114/**
Jeff Brown5912f952013-07-01 19:10:31 -0700115 * Updates a meta state field when a key is pressed or released.
116 */
117extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
118
119/**
120 * Returns true if a key is a meta key like ALT or CAPS_LOCK.
121 */
122extern bool isMetaKey(int32_t keyCode);
123
124} // namespace android
125
126#endif // _LIBINPUT_KEYBOARD_H