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.
5 #include "ui/events/keycodes/keyboard_code_conversion_android.h"
7 #include <android/keycodes.h>
13 // The Android NDK does not provide values for these yet:
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,
24 AKEYCODE_MOVE_HOME
= 122,
25 AKEYCODE_MOVE_END
= 123,
26 AKEYCODE_INSERT
= 124,
27 AKEYCODE_MEDIA_PLAY
= 126,
28 AKEYCODE_MEDIA_PAUSE
= 127,
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,
64 KeyboardCode
KeyboardCodeFromAndroidKeyCode(int keycode
) {
65 // Does not provide all key codes, and does not handle all keys.
73 case AKEYCODE_DPAD_CENTER
:
76 case AKEYCODE_SHIFT_LEFT
:
78 case AKEYCODE_SHIFT_RIGHT
:
80 // Back will serve as escape, although we may not have access to it.
85 case AKEYCODE_MOVE_HOME
:
87 case AKEYCODE_DPAD_LEFT
:
89 case AKEYCODE_DPAD_UP
:
91 case AKEYCODE_DPAD_RIGHT
:
93 case AKEYCODE_DPAD_DOWN
:
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
;
180 case AKEYCODE_SEMICOLON
:
183 return VKEY_OEM_COMMA
;
185 return VKEY_OEM_MINUS
;
186 case AKEYCODE_EQUALS
:
187 return VKEY_OEM_PLUS
;
188 case AKEYCODE_PERIOD
:
189 return VKEY_OEM_PERIOD
;
192 case AKEYCODE_LEFT_BRACKET
:
194 case AKEYCODE_BACKSLASH
:
196 case AKEYCODE_RIGHT_BRACKET
:
199 case AKEYCODE_VOLUME_MUTE
:
200 return VKEY_VOLUME_MUTE
;
201 case AKEYCODE_ESCAPE
:
203 case AKEYCODE_MEDIA_PLAY
:
204 case AKEYCODE_MEDIA_PLAY_PAUSE
:
205 return VKEY_MEDIA_PLAY_PAUSE
;
206 case AKEYCODE_MOVE_END
:
208 case AKEYCODE_ALT_LEFT
:
210 case AKEYCODE_ALT_RIGHT
:
214 case AKEYCODE_APOSTROPHE
:
216 case AKEYCODE_MEDIA_REWIND
:
218 case AKEYCODE_MEDIA_FAST_FORWARD
:
220 case AKEYCODE_PAGE_UP
:
222 case AKEYCODE_PAGE_DOWN
:
224 case AKEYCODE_FORWARD_DEL
:
226 case AKEYCODE_CTRL_LEFT
:
227 return VKEY_LCONTROL
;
228 case AKEYCODE_CTRL_RIGHT
:
229 return VKEY_RCONTROL
;
230 case AKEYCODE_CAPS_LOCK
:
232 case AKEYCODE_SCROLL_LOCK
:
234 case AKEYCODE_META_LEFT
:
236 case AKEYCODE_META_RIGHT
:
240 case AKEYCODE_INSERT
:
266 case AKEYCODE_NUM_LOCK
:
268 case AKEYCODE_NUMPAD_0
:
270 case AKEYCODE_NUMPAD_1
:
272 case AKEYCODE_NUMPAD_2
:
274 case AKEYCODE_NUMPAD_3
:
276 case AKEYCODE_NUMPAD_4
:
278 case AKEYCODE_NUMPAD_5
:
280 case AKEYCODE_NUMPAD_6
:
282 case AKEYCODE_NUMPAD_7
:
284 case AKEYCODE_NUMPAD_8
:
286 case AKEYCODE_NUMPAD_9
:
288 case AKEYCODE_NUMPAD_DIVIDE
:
290 case AKEYCODE_NUMPAD_MULTIPLY
:
291 return VKEY_MULTIPLY
;
292 case AKEYCODE_NUMPAD_SUBTRACT
:
293 return VKEY_SUBTRACT
;
294 case AKEYCODE_NUMPAD_ADD
:
296 case AKEYCODE_NUMPAD_DOT
:
298 case AKEYCODE_CHANNEL_UP
:
300 case AKEYCODE_CHANNEL_DOWN
: