Home | History | Annotate | Download | only in input
      1 /*
      2  * Copyright (C) 2008 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_INPUT_EVENT_LABELS_H
     18 #define _LIBINPUT_INPUT_EVENT_LABELS_H
     19 
     20 #include <input/Input.h>
     21 #include <android/keycodes.h>
     22 
     23 #define DEFINE_KEYCODE(key) { #key, AKEYCODE_##key }
     24 #define DEFINE_AXIS(axis) { #axis, AMOTION_EVENT_AXIS_##axis }
     25 #define DEFINE_LED(led) { #led, ALED_##led }
     26 #define DEFINE_FLAG(flag) { #flag, POLICY_FLAG_##flag }
     27 
     28 namespace android {
     29 
     30 template<typename T, size_t N>
     31 size_t size(T (&)[N]) { return N; }
     32 
     33 struct InputEventLabel {
     34     const char *literal;
     35     int value;
     36 };
     37 
     38 
     39 static const InputEventLabel KEYCODES[] = {
     40     // NOTE: If you add a new keycode here you must also add it to several other files.
     41     //       Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
     42     DEFINE_KEYCODE(UNKNOWN),
     43     DEFINE_KEYCODE(SOFT_LEFT),
     44     DEFINE_KEYCODE(SOFT_RIGHT),
     45     DEFINE_KEYCODE(HOME),
     46     DEFINE_KEYCODE(BACK),
     47     DEFINE_KEYCODE(CALL),
     48     DEFINE_KEYCODE(ENDCALL),
     49     DEFINE_KEYCODE(0),
     50     DEFINE_KEYCODE(1),
     51     DEFINE_KEYCODE(2),
     52     DEFINE_KEYCODE(3),
     53     DEFINE_KEYCODE(4),
     54     DEFINE_KEYCODE(5),
     55     DEFINE_KEYCODE(6),
     56     DEFINE_KEYCODE(7),
     57     DEFINE_KEYCODE(8),
     58     DEFINE_KEYCODE(9),
     59     DEFINE_KEYCODE(STAR),
     60     DEFINE_KEYCODE(POUND),
     61     DEFINE_KEYCODE(DPAD_UP),
     62     DEFINE_KEYCODE(DPAD_DOWN),
     63     DEFINE_KEYCODE(DPAD_LEFT),
     64     DEFINE_KEYCODE(DPAD_RIGHT),
     65     DEFINE_KEYCODE(DPAD_CENTER),
     66     DEFINE_KEYCODE(VOLUME_UP),
     67     DEFINE_KEYCODE(VOLUME_DOWN),
     68     DEFINE_KEYCODE(POWER),
     69     DEFINE_KEYCODE(CAMERA),
     70     DEFINE_KEYCODE(CLEAR),
     71     DEFINE_KEYCODE(A),
     72     DEFINE_KEYCODE(B),
     73     DEFINE_KEYCODE(C),
     74     DEFINE_KEYCODE(D),
     75     DEFINE_KEYCODE(E),
     76     DEFINE_KEYCODE(F),
     77     DEFINE_KEYCODE(G),
     78     DEFINE_KEYCODE(H),
     79     DEFINE_KEYCODE(I),
     80     DEFINE_KEYCODE(J),
     81     DEFINE_KEYCODE(K),
     82     DEFINE_KEYCODE(L),
     83     DEFINE_KEYCODE(M),
     84     DEFINE_KEYCODE(N),
     85     DEFINE_KEYCODE(O),
     86     DEFINE_KEYCODE(P),
     87     DEFINE_KEYCODE(Q),
     88     DEFINE_KEYCODE(R),
     89     DEFINE_KEYCODE(S),
     90     DEFINE_KEYCODE(T),
     91     DEFINE_KEYCODE(U),
     92     DEFINE_KEYCODE(V),
     93     DEFINE_KEYCODE(W),
     94     DEFINE_KEYCODE(X),
     95     DEFINE_KEYCODE(Y),
     96     DEFINE_KEYCODE(Z),
     97     DEFINE_KEYCODE(COMMA),
     98     DEFINE_KEYCODE(PERIOD),
     99     DEFINE_KEYCODE(ALT_LEFT),
    100     DEFINE_KEYCODE(ALT_RIGHT),
    101     DEFINE_KEYCODE(SHIFT_LEFT),
    102     DEFINE_KEYCODE(SHIFT_RIGHT),
    103     DEFINE_KEYCODE(TAB),
    104     DEFINE_KEYCODE(SPACE),
    105     DEFINE_KEYCODE(SYM),
    106     DEFINE_KEYCODE(EXPLORER),
    107     DEFINE_KEYCODE(ENVELOPE),
    108     DEFINE_KEYCODE(ENTER),
    109     DEFINE_KEYCODE(DEL),
    110     DEFINE_KEYCODE(GRAVE),
    111     DEFINE_KEYCODE(MINUS),
    112     DEFINE_KEYCODE(EQUALS),
    113     DEFINE_KEYCODE(LEFT_BRACKET),
    114     DEFINE_KEYCODE(RIGHT_BRACKET),
    115     DEFINE_KEYCODE(BACKSLASH),
    116     DEFINE_KEYCODE(SEMICOLON),
    117     DEFINE_KEYCODE(APOSTROPHE),
    118     DEFINE_KEYCODE(SLASH),
    119     DEFINE_KEYCODE(AT),
    120     DEFINE_KEYCODE(NUM),
    121     DEFINE_KEYCODE(HEADSETHOOK),
    122     DEFINE_KEYCODE(FOCUS),   // *Camera* focus
    123     DEFINE_KEYCODE(PLUS),
    124     DEFINE_KEYCODE(MENU),
    125     DEFINE_KEYCODE(NOTIFICATION),
    126     DEFINE_KEYCODE(SEARCH),
    127     DEFINE_KEYCODE(MEDIA_PLAY_PAUSE),
    128     DEFINE_KEYCODE(MEDIA_STOP),
    129     DEFINE_KEYCODE(MEDIA_NEXT),
    130     DEFINE_KEYCODE(MEDIA_PREVIOUS),
    131     DEFINE_KEYCODE(MEDIA_REWIND),
    132     DEFINE_KEYCODE(MEDIA_FAST_FORWARD),
    133     DEFINE_KEYCODE(MUTE),
    134     DEFINE_KEYCODE(PAGE_UP),
    135     DEFINE_KEYCODE(PAGE_DOWN),
    136     DEFINE_KEYCODE(PICTSYMBOLS),
    137     DEFINE_KEYCODE(SWITCH_CHARSET),
    138     DEFINE_KEYCODE(BUTTON_A),
    139     DEFINE_KEYCODE(BUTTON_B),
    140     DEFINE_KEYCODE(BUTTON_C),
    141     DEFINE_KEYCODE(BUTTON_X),
    142     DEFINE_KEYCODE(BUTTON_Y),
    143     DEFINE_KEYCODE(BUTTON_Z),
    144     DEFINE_KEYCODE(BUTTON_L1),
    145     DEFINE_KEYCODE(BUTTON_R1),
    146     DEFINE_KEYCODE(BUTTON_L2),
    147     DEFINE_KEYCODE(BUTTON_R2),
    148     DEFINE_KEYCODE(BUTTON_THUMBL),
    149     DEFINE_KEYCODE(BUTTON_THUMBR),
    150     DEFINE_KEYCODE(BUTTON_START),
    151     DEFINE_KEYCODE(BUTTON_SELECT),
    152     DEFINE_KEYCODE(BUTTON_MODE),
    153     DEFINE_KEYCODE(ESCAPE),
    154     DEFINE_KEYCODE(FORWARD_DEL),
    155     DEFINE_KEYCODE(CTRL_LEFT),
    156     DEFINE_KEYCODE(CTRL_RIGHT),
    157     DEFINE_KEYCODE(CAPS_LOCK),
    158     DEFINE_KEYCODE(SCROLL_LOCK),
    159     DEFINE_KEYCODE(META_LEFT),
    160     DEFINE_KEYCODE(META_RIGHT),
    161     DEFINE_KEYCODE(FUNCTION),
    162     DEFINE_KEYCODE(SYSRQ),
    163     DEFINE_KEYCODE(BREAK),
    164     DEFINE_KEYCODE(MOVE_HOME),
    165     DEFINE_KEYCODE(MOVE_END),
    166     DEFINE_KEYCODE(INSERT),
    167     DEFINE_KEYCODE(FORWARD),
    168     DEFINE_KEYCODE(MEDIA_PLAY),
    169     DEFINE_KEYCODE(MEDIA_PAUSE),
    170     DEFINE_KEYCODE(MEDIA_CLOSE),
    171     DEFINE_KEYCODE(MEDIA_EJECT),
    172     DEFINE_KEYCODE(MEDIA_RECORD),
    173     DEFINE_KEYCODE(F1),
    174     DEFINE_KEYCODE(F2),
    175     DEFINE_KEYCODE(F3),
    176     DEFINE_KEYCODE(F4),
    177     DEFINE_KEYCODE(F5),
    178     DEFINE_KEYCODE(F6),
    179     DEFINE_KEYCODE(F7),
    180     DEFINE_KEYCODE(F8),
    181     DEFINE_KEYCODE(F9),
    182     DEFINE_KEYCODE(F10),
    183     DEFINE_KEYCODE(F11),
    184     DEFINE_KEYCODE(F12),
    185     DEFINE_KEYCODE(NUM_LOCK),
    186     DEFINE_KEYCODE(NUMPAD_0),
    187     DEFINE_KEYCODE(NUMPAD_1),
    188     DEFINE_KEYCODE(NUMPAD_2),
    189     DEFINE_KEYCODE(NUMPAD_3),
    190     DEFINE_KEYCODE(NUMPAD_4),
    191     DEFINE_KEYCODE(NUMPAD_5),
    192     DEFINE_KEYCODE(NUMPAD_6),
    193     DEFINE_KEYCODE(NUMPAD_7),
    194     DEFINE_KEYCODE(NUMPAD_8),
    195     DEFINE_KEYCODE(NUMPAD_9),
    196     DEFINE_KEYCODE(NUMPAD_DIVIDE),
    197     DEFINE_KEYCODE(NUMPAD_MULTIPLY),
    198     DEFINE_KEYCODE(NUMPAD_SUBTRACT),
    199     DEFINE_KEYCODE(NUMPAD_ADD),
    200     DEFINE_KEYCODE(NUMPAD_DOT),
    201     DEFINE_KEYCODE(NUMPAD_COMMA),
    202     DEFINE_KEYCODE(NUMPAD_ENTER),
    203     DEFINE_KEYCODE(NUMPAD_EQUALS),
    204     DEFINE_KEYCODE(NUMPAD_LEFT_PAREN),
    205     DEFINE_KEYCODE(NUMPAD_RIGHT_PAREN),
    206     DEFINE_KEYCODE(VOLUME_MUTE),
    207     DEFINE_KEYCODE(INFO),
    208     DEFINE_KEYCODE(CHANNEL_UP),
    209     DEFINE_KEYCODE(CHANNEL_DOWN),
    210     DEFINE_KEYCODE(ZOOM_IN),
    211     DEFINE_KEYCODE(ZOOM_OUT),
    212     DEFINE_KEYCODE(TV),
    213     DEFINE_KEYCODE(WINDOW),
    214     DEFINE_KEYCODE(GUIDE),
    215     DEFINE_KEYCODE(DVR),
    216     DEFINE_KEYCODE(BOOKMARK),
    217     DEFINE_KEYCODE(CAPTIONS),
    218     DEFINE_KEYCODE(SETTINGS),
    219     DEFINE_KEYCODE(TV_POWER),
    220     DEFINE_KEYCODE(TV_INPUT),
    221     DEFINE_KEYCODE(STB_POWER),
    222     DEFINE_KEYCODE(STB_INPUT),
    223     DEFINE_KEYCODE(AVR_POWER),
    224     DEFINE_KEYCODE(AVR_INPUT),
    225     DEFINE_KEYCODE(PROG_RED),
    226     DEFINE_KEYCODE(PROG_GREEN),
    227     DEFINE_KEYCODE(PROG_YELLOW),
    228     DEFINE_KEYCODE(PROG_BLUE),
    229     DEFINE_KEYCODE(APP_SWITCH),
    230     DEFINE_KEYCODE(BUTTON_1),
    231     DEFINE_KEYCODE(BUTTON_2),
    232     DEFINE_KEYCODE(BUTTON_3),
    233     DEFINE_KEYCODE(BUTTON_4),
    234     DEFINE_KEYCODE(BUTTON_5),
    235     DEFINE_KEYCODE(BUTTON_6),
    236     DEFINE_KEYCODE(BUTTON_7),
    237     DEFINE_KEYCODE(BUTTON_8),
    238     DEFINE_KEYCODE(BUTTON_9),
    239     DEFINE_KEYCODE(BUTTON_10),
    240     DEFINE_KEYCODE(BUTTON_11),
    241     DEFINE_KEYCODE(BUTTON_12),
    242     DEFINE_KEYCODE(BUTTON_13),
    243     DEFINE_KEYCODE(BUTTON_14),
    244     DEFINE_KEYCODE(BUTTON_15),
    245     DEFINE_KEYCODE(BUTTON_16),
    246     DEFINE_KEYCODE(LANGUAGE_SWITCH),
    247     DEFINE_KEYCODE(MANNER_MODE),
    248     DEFINE_KEYCODE(3D_MODE),
    249     DEFINE_KEYCODE(CONTACTS),
    250     DEFINE_KEYCODE(CALENDAR),
    251     DEFINE_KEYCODE(MUSIC),
    252     DEFINE_KEYCODE(CALCULATOR),
    253     DEFINE_KEYCODE(ZENKAKU_HANKAKU),
    254     DEFINE_KEYCODE(EISU),
    255     DEFINE_KEYCODE(MUHENKAN),
    256     DEFINE_KEYCODE(HENKAN),
    257     DEFINE_KEYCODE(KATAKANA_HIRAGANA),
    258     DEFINE_KEYCODE(YEN),
    259     DEFINE_KEYCODE(RO),
    260     DEFINE_KEYCODE(KANA),
    261     DEFINE_KEYCODE(ASSIST),
    262     DEFINE_KEYCODE(BRIGHTNESS_DOWN),
    263     DEFINE_KEYCODE(BRIGHTNESS_UP),
    264     DEFINE_KEYCODE(MEDIA_AUDIO_TRACK),
    265     DEFINE_KEYCODE(SLEEP),
    266     DEFINE_KEYCODE(WAKEUP),
    267     DEFINE_KEYCODE(PAIRING),
    268     DEFINE_KEYCODE(MEDIA_TOP_MENU),
    269     DEFINE_KEYCODE(11),
    270     DEFINE_KEYCODE(12),
    271     DEFINE_KEYCODE(LAST_CHANNEL),
    272     DEFINE_KEYCODE(TV_DATA_SERVICE),
    273     DEFINE_KEYCODE(VOICE_ASSIST),
    274     DEFINE_KEYCODE(TV_RADIO_SERVICE),
    275     DEFINE_KEYCODE(TV_TELETEXT),
    276     DEFINE_KEYCODE(TV_NUMBER_ENTRY),
    277     DEFINE_KEYCODE(TV_TERRESTRIAL_ANALOG),
    278     DEFINE_KEYCODE(TV_TERRESTRIAL_DIGITAL),
    279     DEFINE_KEYCODE(TV_SATELLITE),
    280     DEFINE_KEYCODE(TV_SATELLITE_BS),
    281     DEFINE_KEYCODE(TV_SATELLITE_CS),
    282     DEFINE_KEYCODE(TV_SATELLITE_SERVICE),
    283     DEFINE_KEYCODE(TV_NETWORK),
    284     DEFINE_KEYCODE(TV_ANTENNA_CABLE),
    285     DEFINE_KEYCODE(TV_INPUT_HDMI_1),
    286     DEFINE_KEYCODE(TV_INPUT_HDMI_2),
    287     DEFINE_KEYCODE(TV_INPUT_HDMI_3),
    288     DEFINE_KEYCODE(TV_INPUT_HDMI_4),
    289     DEFINE_KEYCODE(TV_INPUT_COMPOSITE_1),
    290     DEFINE_KEYCODE(TV_INPUT_COMPOSITE_2),
    291     DEFINE_KEYCODE(TV_INPUT_COMPONENT_1),
    292     DEFINE_KEYCODE(TV_INPUT_COMPONENT_2),
    293     DEFINE_KEYCODE(TV_INPUT_VGA_1),
    294     DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION),
    295     DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION_MIX_UP),
    296     DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION_MIX_DOWN),
    297     DEFINE_KEYCODE(TV_ZOOM_MODE),
    298     DEFINE_KEYCODE(TV_CONTENTS_MENU),
    299     DEFINE_KEYCODE(TV_MEDIA_CONTEXT_MENU),
    300     DEFINE_KEYCODE(TV_TIMER_PROGRAMMING),
    301     DEFINE_KEYCODE(HELP),
    302 
    303     { NULL, 0 }
    304 };
    305 
    306 static const InputEventLabel AXES[] = {
    307     DEFINE_AXIS(X),
    308     DEFINE_AXIS(Y),
    309     DEFINE_AXIS(PRESSURE),
    310     DEFINE_AXIS(SIZE),
    311     DEFINE_AXIS(TOUCH_MAJOR),
    312     DEFINE_AXIS(TOUCH_MINOR),
    313     DEFINE_AXIS(TOOL_MAJOR),
    314     DEFINE_AXIS(TOOL_MINOR),
    315     DEFINE_AXIS(ORIENTATION),
    316     DEFINE_AXIS(VSCROLL),
    317     DEFINE_AXIS(HSCROLL),
    318     DEFINE_AXIS(Z),
    319     DEFINE_AXIS(RX),
    320     DEFINE_AXIS(RY),
    321     DEFINE_AXIS(RZ),
    322     DEFINE_AXIS(HAT_X),
    323     DEFINE_AXIS(HAT_Y),
    324     DEFINE_AXIS(LTRIGGER),
    325     DEFINE_AXIS(RTRIGGER),
    326     DEFINE_AXIS(THROTTLE),
    327     DEFINE_AXIS(RUDDER),
    328     DEFINE_AXIS(WHEEL),
    329     DEFINE_AXIS(GAS),
    330     DEFINE_AXIS(BRAKE),
    331     DEFINE_AXIS(DISTANCE),
    332     DEFINE_AXIS(TILT),
    333     DEFINE_AXIS(GENERIC_1),
    334     DEFINE_AXIS(GENERIC_2),
    335     DEFINE_AXIS(GENERIC_3),
    336     DEFINE_AXIS(GENERIC_4),
    337     DEFINE_AXIS(GENERIC_5),
    338     DEFINE_AXIS(GENERIC_6),
    339     DEFINE_AXIS(GENERIC_7),
    340     DEFINE_AXIS(GENERIC_8),
    341     DEFINE_AXIS(GENERIC_9),
    342     DEFINE_AXIS(GENERIC_10),
    343     DEFINE_AXIS(GENERIC_11),
    344     DEFINE_AXIS(GENERIC_12),
    345     DEFINE_AXIS(GENERIC_13),
    346     DEFINE_AXIS(GENERIC_14),
    347     DEFINE_AXIS(GENERIC_15),
    348     DEFINE_AXIS(GENERIC_16),
    349 
    350     // NOTE: If you add a new axis here you must also add it to several other files.
    351     //       Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list.
    352     { NULL, 0 }
    353 };
    354 
    355 static const InputEventLabel LEDS[] = {
    356     DEFINE_LED(NUM_LOCK),
    357     DEFINE_LED(CAPS_LOCK),
    358     DEFINE_LED(SCROLL_LOCK),
    359     DEFINE_LED(COMPOSE),
    360     DEFINE_LED(KANA),
    361     DEFINE_LED(SLEEP),
    362     DEFINE_LED(SUSPEND),
    363     DEFINE_LED(MUTE),
    364     DEFINE_LED(MISC),
    365     DEFINE_LED(MAIL),
    366     DEFINE_LED(CHARGING),
    367     DEFINE_LED(CONTROLLER_1),
    368     DEFINE_LED(CONTROLLER_2),
    369     DEFINE_LED(CONTROLLER_3),
    370     DEFINE_LED(CONTROLLER_4),
    371 
    372     // NOTE: If you add new LEDs here, you must also add them to Input.h
    373     { NULL, 0 }
    374 };
    375 
    376 static const InputEventLabel FLAGS[] = {
    377     DEFINE_FLAG(VIRTUAL),
    378     DEFINE_FLAG(FUNCTION),
    379 
    380     { NULL, 0 }
    381 };
    382 
    383 static int lookupValueByLabel(const char* literal, const InputEventLabel *list) {
    384     while (list->literal) {
    385         if (strcmp(literal, list->literal) == 0) {
    386             return list->value;
    387         }
    388         list++;
    389     }
    390     return list->value;
    391 }
    392 
    393 static const char* lookupLabelByValue(int value, const InputEventLabel* list) {
    394     while (list->literal) {
    395         if (list->value == value) {
    396             return list->literal;
    397         }
    398         list++;
    399     }
    400     return NULL;
    401 }
    402 
    403 static int32_t getKeyCodeByLabel(const char* label) {
    404     return int32_t(lookupValueByLabel(label, KEYCODES));
    405 }
    406 
    407 static const char* getLabelByKeyCode(int32_t keyCode) {
    408     if (keyCode >= 0 && keyCode < size(KEYCODES)) {
    409         return KEYCODES[keyCode].literal;
    410     }
    411     return NULL;
    412 }
    413 
    414 static uint32_t getKeyFlagByLabel(const char* label) {
    415     return uint32_t(lookupValueByLabel(label, FLAGS));
    416 }
    417 
    418 static int32_t getAxisByLabel(const char* label) {
    419     return int32_t(lookupValueByLabel(label, AXES));
    420 }
    421 
    422 static const char* getAxisLabel(int32_t axisId) {
    423     return lookupLabelByValue(axisId, AXES);
    424 }
    425 
    426 static int32_t getLedByLabel(const char* label) {
    427     return int32_t(lookupValueByLabel(label, LEDS));
    428 }
    429 
    430 
    431 } // namespace android
    432 #endif // _LIBINPUT_INPUT_EVENT_LABELS_H
    433