blob: 6537a8f109a75849d2a2ca1756a52154fffb7836 [file] [log] [blame]
Jeff Brown6b53e8d2010-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
Mathias Agopianb93a03f82012-02-17 15:34:57 -080017#ifndef _ANDROIDFW_KEYBOARD_H
18#define _ANDROIDFW_KEYBOARD_H
Jeff Brown6b53e8d2010-11-10 16:03:06 -080019
Mathias Agopianb93a03f82012-02-17 15:34:57 -080020#include <androidfw/Input.h>
Jeff Brown9f25b7f2012-04-10 14:30:49 -070021#include <androidfw/InputDevice.h>
Jeff Brown6b53e8d2010-11-10 16:03:06 -080022#include <utils/Errors.h>
23#include <utils/String8.h>
Jeff Brown47e6b1b2010-11-29 17:37:49 -080024#include <utils/PropertyMap.h>
Jeff Brown6b53e8d2010-11-10 16:03:06 -080025
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
Jeff Brown90655042010-12-02 13:50:46 -080037class KeyLayoutMap;
38class KeyCharacterMap;
39
40/**
41 * Loads the key layout map and key character map for a keyboard device.
42 */
43class KeyMap {
44public:
Jeff Brown6b53e8d2010-11-10 16:03:06 -080045 String8 keyLayoutFile;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070046 sp<KeyLayoutMap> keyLayoutMap;
Jeff Brown90655042010-12-02 13:50:46 -080047
Jeff Brown6b53e8d2010-11-10 16:03:06 -080048 String8 keyCharacterMapFile;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070049 sp<KeyCharacterMap> keyCharacterMap;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080050
Jeff Brown90655042010-12-02 13:50:46 -080051 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();
Jeff Brown6b53e8d2010-11-10 16:03:06 -080059 }
Jeff Brown47e6b1b2010-11-29 17:37:49 -080060
Jeff Brown90655042010-12-02 13:50:46 -080061 inline bool haveKeyCharacterMap() const {
62 return !keyCharacterMapFile.isEmpty();
Jeff Brown47e6b1b2010-11-29 17:37:49 -080063 }
Jeff Brown90655042010-12-02 13:50:46 -080064
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);
Jeff Brown6b53e8d2010-11-10 16:03:06 -080076};
77
78/**
Jeff Brown90655042010-12-02 13:50:46 -080079 * Returns true if the keyboard is eligible for use as a built-in keyboard.
Jeff Brown6b53e8d2010-11-10 16:03:06 -080080 */
Jeff Brown90655042010-12-02 13:50:46 -080081extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
82 const PropertyMap* deviceConfiguration, const KeyMap* keyMap);
Jeff Brown6b53e8d2010-11-10 16:03:06 -080083
84/**
Jeff Brown6b53e8d2010-11-10 16:03:06 -080085 * 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/**
Jeff Brown6f2fba42011-02-19 01:08:02 -080097 * Gets a axis by its short form label, eg. "X".
98 * Returns -1 if unknown.
99 */
100extern int32_t getAxisByLabel(const char* label);
101
102/**
103 * Gets a axis label by its id.
104 * Returns NULL if unknown.
105 */
106extern const char* getAxisLabel(int32_t axisId);
107
108/**
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800109 * Updates a meta state field when a key is pressed or released.
110 */
111extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
112
Jeff Brown05dc66a2011-03-02 14:41:58 -0800113/**
114 * Returns true if a key is a meta key like ALT or CAPS_LOCK.
115 */
116extern bool isMetaKey(int32_t keyCode);
117
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800118} // namespace android
119
Mathias Agopianb93a03f82012-02-17 15:34:57 -0800120#endif // _ANDROIDFW_KEYBOARD_H