Home | History | Annotate | Download | only in ui
      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 
     56     inline bool haveKeyLayout() const {
     57         return !keyLayoutFile.isEmpty();
     58     }
     59 
     60     inline bool haveKeyCharacterMap() const {
     61         return !keyCharacterMapFile.isEmpty();
     62     }
     63 
     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  * Gets a key code by its short form label, eg. "HOME".
     85  * Returns 0 if unknown.
     86  */
     87 extern int32_t getKeyCodeByLabel(const char* label);
     88 
     89 /**
     90  * Gets a key flag by its short form label, eg. "WAKE".
     91  * Returns 0 if unknown.
     92  */
     93 extern uint32_t getKeyFlagByLabel(const char* label);
     94 
     95 /**
     96  * Gets a axis by its short form label, eg. "X".
     97  * Returns -1 if unknown.
     98  */
     99 extern int32_t getAxisByLabel(const char* label);
    100 
    101 /**
    102  * Gets a axis label by its id.
    103  * Returns NULL if unknown.
    104  */
    105 extern const char* getAxisLabel(int32_t axisId);
    106 
    107 /**
    108  * Updates a meta state field when a key is pressed or released.
    109  */
    110 extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
    111 
    112 /**
    113  * Returns true if a key is a meta key like ALT or CAPS_LOCK.
    114  */
    115 extern bool isMetaKey(int32_t keyCode);
    116 
    117 } // namespace android
    118 
    119 #endif // _UI_KEYBOARD_H
    120