Home | History | Annotate | Download | only in keycodes
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "ui/events/keycodes/keyboard_code_conversion_android.h"
      6 
      7 #include <android/keycodes.h>
      8 
      9 namespace ui {
     10 
     11 namespace {
     12 
     13 // The Android NDK does not provide values for these yet:
     14 enum {
     15   AKEYCODE_ESCAPE          = 111,
     16   AKEYCODE_FORWARD_DEL     = 112,
     17   AKEYCODE_CTRL_LEFT       = 113,
     18   AKEYCODE_CTRL_RIGHT      = 114,
     19   AKEYCODE_CAPS_LOCK       = 115,
     20   AKEYCODE_SCROLL_LOCK     = 116,
     21   AKEYCODE_META_LEFT       = 117,
     22   AKEYCODE_META_RIGHT      = 118,
     23   AKEYCODE_BREAK           = 121,
     24   AKEYCODE_MOVE_HOME       = 122,
     25   AKEYCODE_MOVE_END        = 123,
     26   AKEYCODE_INSERT          = 124,
     27   AKEYCODE_MEDIA_PLAY      = 126,
     28   AKEYCODE_MEDIA_PAUSE     = 127,
     29   AKEYCODE_F1              = 131,
     30   AKEYCODE_F2              = 132,
     31   AKEYCODE_F3              = 133,
     32   AKEYCODE_F4              = 134,
     33   AKEYCODE_F5              = 135,
     34   AKEYCODE_F6              = 136,
     35   AKEYCODE_F7              = 137,
     36   AKEYCODE_F8              = 138,
     37   AKEYCODE_F9              = 139,
     38   AKEYCODE_F10             = 140,
     39   AKEYCODE_F11             = 141,
     40   AKEYCODE_F12             = 142,
     41   AKEYCODE_NUM_LOCK        = 143,
     42   AKEYCODE_NUMPAD_0        = 144,
     43   AKEYCODE_NUMPAD_1        = 145,
     44   AKEYCODE_NUMPAD_2        = 146,
     45   AKEYCODE_NUMPAD_3        = 147,
     46   AKEYCODE_NUMPAD_4        = 148,
     47   AKEYCODE_NUMPAD_5        = 149,
     48   AKEYCODE_NUMPAD_6        = 150,
     49   AKEYCODE_NUMPAD_7        = 151,
     50   AKEYCODE_NUMPAD_8        = 152,
     51   AKEYCODE_NUMPAD_9        = 153,
     52   AKEYCODE_NUMPAD_DIVIDE   = 154,
     53   AKEYCODE_NUMPAD_MULTIPLY = 155,
     54   AKEYCODE_NUMPAD_SUBTRACT = 156,
     55   AKEYCODE_NUMPAD_ADD      = 157,
     56   AKEYCODE_NUMPAD_DOT      = 158,
     57   AKEYCODE_VOLUME_MUTE     = 164,
     58   AKEYCODE_CHANNEL_UP      = 166,
     59   AKEYCODE_CHANNEL_DOWN    = 167,
     60 };
     61 
     62 }  // namespace
     63 
     64 KeyboardCode KeyboardCodeFromAndroidKeyCode(int keycode) {
     65   // Does not provide all key codes, and does not handle all keys.
     66   switch (keycode) {
     67     case AKEYCODE_DEL:
     68       return VKEY_BACK;
     69     case AKEYCODE_TAB:
     70       return VKEY_TAB;
     71     case AKEYCODE_CLEAR:
     72       return VKEY_CLEAR;
     73     case AKEYCODE_DPAD_CENTER:
     74     case AKEYCODE_ENTER:
     75       return VKEY_RETURN;
     76     case AKEYCODE_SHIFT_LEFT:
     77       return VKEY_LSHIFT;
     78     case AKEYCODE_SHIFT_RIGHT:
     79       return VKEY_RSHIFT;
     80     // Back will serve as escape, although we may not have access to it.
     81     case AKEYCODE_BACK:
     82       return VKEY_ESCAPE;
     83     case AKEYCODE_SPACE:
     84       return VKEY_SPACE;
     85     case AKEYCODE_MOVE_HOME:
     86       return VKEY_HOME;
     87     case AKEYCODE_DPAD_LEFT:
     88       return VKEY_LEFT;
     89     case AKEYCODE_DPAD_UP:
     90       return VKEY_UP;
     91     case AKEYCODE_DPAD_RIGHT:
     92       return VKEY_RIGHT;
     93     case AKEYCODE_DPAD_DOWN:
     94       return VKEY_DOWN;
     95     case AKEYCODE_0:
     96       return VKEY_0;
     97     case AKEYCODE_1:
     98       return VKEY_1;
     99     case AKEYCODE_2:
    100       return VKEY_2;
    101     case AKEYCODE_3:
    102       return VKEY_3;
    103     case AKEYCODE_4:
    104       return VKEY_4;
    105     case AKEYCODE_5:
    106       return VKEY_5;
    107     case AKEYCODE_6:
    108       return VKEY_6;
    109     case AKEYCODE_7:
    110       return VKEY_7;
    111     case AKEYCODE_8:
    112       return VKEY_8;
    113     case AKEYCODE_9:
    114       return VKEY_9;
    115     case AKEYCODE_A:
    116       return VKEY_A;
    117     case AKEYCODE_B:
    118       return VKEY_B;
    119     case AKEYCODE_C:
    120       return VKEY_C;
    121     case AKEYCODE_D:
    122       return VKEY_D;
    123     case AKEYCODE_E:
    124       return VKEY_E;
    125     case AKEYCODE_F:
    126       return VKEY_F;
    127     case AKEYCODE_G:
    128       return VKEY_G;
    129     case AKEYCODE_H:
    130       return VKEY_H;
    131     case AKEYCODE_I:
    132       return VKEY_I;
    133     case AKEYCODE_J:
    134       return VKEY_J;
    135     case AKEYCODE_K:
    136       return VKEY_K;
    137     case AKEYCODE_L:
    138       return VKEY_L;
    139     case AKEYCODE_M:
    140       return VKEY_M;
    141     case AKEYCODE_N:
    142       return VKEY_N;
    143     case AKEYCODE_O:
    144       return VKEY_O;
    145     case AKEYCODE_P:
    146       return VKEY_P;
    147     case AKEYCODE_Q:
    148       return VKEY_Q;
    149     case AKEYCODE_R:
    150       return VKEY_R;
    151     case AKEYCODE_S:
    152       return VKEY_S;
    153     case AKEYCODE_T:
    154       return VKEY_T;
    155     case AKEYCODE_U:
    156       return VKEY_U;
    157     case AKEYCODE_V:
    158       return VKEY_V;
    159     case AKEYCODE_W:
    160       return VKEY_W;
    161     case AKEYCODE_X:
    162       return VKEY_X;
    163     case AKEYCODE_Y:
    164       return VKEY_Y;
    165     case AKEYCODE_Z:
    166       return VKEY_Z;
    167     case AKEYCODE_VOLUME_DOWN:
    168       return VKEY_VOLUME_DOWN;
    169     case AKEYCODE_VOLUME_UP:
    170       return VKEY_VOLUME_UP;
    171     case AKEYCODE_MEDIA_NEXT:
    172       return VKEY_MEDIA_NEXT_TRACK;
    173     case AKEYCODE_MEDIA_PREVIOUS:
    174       return VKEY_MEDIA_PREV_TRACK;
    175     case AKEYCODE_MEDIA_STOP:
    176       return VKEY_MEDIA_STOP;
    177     case AKEYCODE_MEDIA_PAUSE:
    178       return VKEY_MEDIA_PLAY_PAUSE;
    179     // Colon key.
    180     case AKEYCODE_SEMICOLON:
    181       return VKEY_OEM_1;
    182     case AKEYCODE_COMMA:
    183       return VKEY_OEM_COMMA;
    184     case AKEYCODE_MINUS:
    185       return VKEY_OEM_MINUS;
    186     case AKEYCODE_EQUALS:
    187       return VKEY_OEM_PLUS;
    188     case AKEYCODE_PERIOD:
    189       return VKEY_OEM_PERIOD;
    190     case AKEYCODE_SLASH:
    191       return VKEY_OEM_2;
    192     case AKEYCODE_LEFT_BRACKET:
    193       return VKEY_OEM_4;
    194     case AKEYCODE_BACKSLASH:
    195       return VKEY_OEM_5;
    196     case AKEYCODE_RIGHT_BRACKET:
    197       return VKEY_OEM_6;
    198     case AKEYCODE_MUTE:
    199     case AKEYCODE_VOLUME_MUTE:
    200       return VKEY_VOLUME_MUTE;
    201     case AKEYCODE_ESCAPE:
    202       return VKEY_ESCAPE;
    203     case AKEYCODE_MEDIA_PLAY:
    204     case AKEYCODE_MEDIA_PLAY_PAUSE:
    205       return VKEY_MEDIA_PLAY_PAUSE;
    206     case AKEYCODE_MOVE_END:
    207       return VKEY_END;
    208     case AKEYCODE_ALT_LEFT:
    209       return VKEY_LMENU;
    210     case AKEYCODE_ALT_RIGHT:
    211       return VKEY_RMENU;
    212     case AKEYCODE_GRAVE:
    213       return VKEY_OEM_3;
    214     case AKEYCODE_APOSTROPHE:
    215       return VKEY_OEM_3;
    216     case AKEYCODE_MEDIA_REWIND:
    217       return VKEY_OEM_103;
    218     case AKEYCODE_MEDIA_FAST_FORWARD:
    219       return VKEY_OEM_104;
    220     case AKEYCODE_PAGE_UP:
    221       return VKEY_PRIOR;
    222     case AKEYCODE_PAGE_DOWN:
    223       return VKEY_NEXT;
    224     case AKEYCODE_FORWARD_DEL:
    225       return VKEY_DELETE;
    226     case AKEYCODE_CTRL_LEFT:
    227       return VKEY_LCONTROL;
    228     case AKEYCODE_CTRL_RIGHT:
    229       return VKEY_RCONTROL;
    230     case AKEYCODE_CAPS_LOCK:
    231       return VKEY_CAPITAL;
    232     case AKEYCODE_SCROLL_LOCK:
    233       return VKEY_SCROLL;
    234     case AKEYCODE_META_LEFT:
    235       return VKEY_LWIN;
    236     case AKEYCODE_META_RIGHT:
    237       return VKEY_RWIN;
    238     case AKEYCODE_BREAK:
    239       return VKEY_PAUSE;
    240     case AKEYCODE_INSERT:
    241       return VKEY_INSERT;
    242     case AKEYCODE_F1:
    243       return VKEY_F1;
    244     case AKEYCODE_F2:
    245       return VKEY_F2;
    246     case AKEYCODE_F3:
    247       return VKEY_F3;
    248     case AKEYCODE_F4:
    249       return VKEY_F4;
    250     case AKEYCODE_F5:
    251       return VKEY_F5;
    252     case AKEYCODE_F6:
    253       return VKEY_F6;
    254     case AKEYCODE_F7:
    255       return VKEY_F7;
    256     case AKEYCODE_F8:
    257       return VKEY_F8;
    258     case AKEYCODE_F9:
    259       return VKEY_F9;
    260     case AKEYCODE_F10:
    261       return VKEY_F10;
    262     case AKEYCODE_F11:
    263       return VKEY_F11;
    264     case AKEYCODE_F12:
    265       return VKEY_F12;
    266     case AKEYCODE_NUM_LOCK:
    267       return VKEY_NUMLOCK;
    268     case AKEYCODE_NUMPAD_0:
    269       return VKEY_NUMPAD0;
    270     case AKEYCODE_NUMPAD_1:
    271       return VKEY_NUMPAD1;
    272     case AKEYCODE_NUMPAD_2:
    273       return VKEY_NUMPAD2;
    274     case AKEYCODE_NUMPAD_3:
    275       return VKEY_NUMPAD3;
    276     case AKEYCODE_NUMPAD_4:
    277       return VKEY_NUMPAD4;
    278     case AKEYCODE_NUMPAD_5:
    279       return VKEY_NUMPAD5;
    280     case AKEYCODE_NUMPAD_6:
    281       return VKEY_NUMPAD6;
    282     case AKEYCODE_NUMPAD_7:
    283       return VKEY_NUMPAD7;
    284     case AKEYCODE_NUMPAD_8:
    285       return VKEY_NUMPAD8;
    286     case AKEYCODE_NUMPAD_9:
    287       return VKEY_NUMPAD9;
    288     case AKEYCODE_NUMPAD_DIVIDE:
    289       return VKEY_DIVIDE;
    290     case AKEYCODE_NUMPAD_MULTIPLY:
    291       return VKEY_MULTIPLY;
    292     case AKEYCODE_NUMPAD_SUBTRACT:
    293       return VKEY_SUBTRACT;
    294     case AKEYCODE_NUMPAD_ADD:
    295       return VKEY_ADD;
    296     case AKEYCODE_NUMPAD_DOT:
    297       return VKEY_DECIMAL;
    298     case AKEYCODE_CHANNEL_UP:
    299       return VKEY_PRIOR;
    300     case AKEYCODE_CHANNEL_DOWN:
    301       return VKEY_NEXT;
    302     default:
    303       return VKEY_UNKNOWN;
    304   }
    305 }
    306 
    307 }  // namespace ui
    308