michael@0: /* michael@0: * Copyright (C) 2010 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef _ANDROIDFW_KEYBOARD_H michael@0: #define _ANDROIDFW_KEYBOARD_H michael@0: michael@0: #include "Input.h" michael@0: #include "InputDevice.h" michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: namespace android { michael@0: michael@0: enum { michael@0: /* Device id of the built in keyboard. */ michael@0: DEVICE_ID_BUILT_IN_KEYBOARD = 0, michael@0: michael@0: /* Device id of a generic virtual keyboard with a full layout that can be used michael@0: * to synthesize key events. */ michael@0: DEVICE_ID_VIRTUAL_KEYBOARD = -1, michael@0: }; michael@0: michael@0: class KeyLayoutMap; michael@0: class KeyCharacterMap; michael@0: michael@0: /** michael@0: * Loads the key layout map and key character map for a keyboard device. michael@0: */ michael@0: class KeyMap { michael@0: public: michael@0: String8 keyLayoutFile; michael@0: sp keyLayoutMap; michael@0: michael@0: String8 keyCharacterMapFile; michael@0: sp keyCharacterMap; michael@0: michael@0: KeyMap(); michael@0: ~KeyMap(); michael@0: michael@0: status_t load(const InputDeviceIdentifier& deviceIdenfier, michael@0: const PropertyMap* deviceConfiguration); michael@0: michael@0: inline bool haveKeyLayout() const { michael@0: return !keyLayoutFile.isEmpty(); michael@0: } michael@0: michael@0: inline bool haveKeyCharacterMap() const { michael@0: return !keyCharacterMapFile.isEmpty(); michael@0: } michael@0: michael@0: inline bool isComplete() const { michael@0: return haveKeyLayout() && haveKeyCharacterMap(); michael@0: } michael@0: michael@0: private: michael@0: bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const String8& name); michael@0: status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const String8& name); michael@0: status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier, michael@0: const String8& name); michael@0: String8 getPath(const InputDeviceIdentifier& deviceIdentifier, michael@0: const String8& name, InputDeviceConfigurationFileType type); michael@0: }; michael@0: michael@0: /** michael@0: * Returns true if the keyboard is eligible for use as a built-in keyboard. michael@0: */ michael@0: extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier, michael@0: const PropertyMap* deviceConfiguration, const KeyMap* keyMap); michael@0: michael@0: /** michael@0: * Gets a key code by its short form label, eg. "HOME". michael@0: * Returns 0 if unknown. michael@0: */ michael@0: extern int32_t getKeyCodeByLabel(const char* label); michael@0: michael@0: /** michael@0: * Gets a key flag by its short form label, eg. "WAKE". michael@0: * Returns 0 if unknown. michael@0: */ michael@0: extern uint32_t getKeyFlagByLabel(const char* label); michael@0: michael@0: /** michael@0: * Gets a axis by its short form label, eg. "X". michael@0: * Returns -1 if unknown. michael@0: */ michael@0: extern int32_t getAxisByLabel(const char* label); michael@0: michael@0: /** michael@0: * Gets a axis label by its id. michael@0: * Returns NULL if unknown. michael@0: */ michael@0: extern const char* getAxisLabel(int32_t axisId); michael@0: michael@0: /** michael@0: * Updates a meta state field when a key is pressed or released. michael@0: */ michael@0: extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState); michael@0: michael@0: /** michael@0: * Returns true if a key is a meta key like ALT or CAPS_LOCK. michael@0: */ michael@0: extern bool isMetaKey(int32_t keyCode); michael@0: michael@0: } // namespace android michael@0: michael@0: #endif // _ANDROIDFW_KEYBOARD_H