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
:
81 return VKEY_BROWSER_BACK
;
82 case AKEYCODE_FORWARD
:
83 return VKEY_BROWSER_FORWARD
;
86 case AKEYCODE_MOVE_HOME
:
88 case AKEYCODE_DPAD_LEFT
:
90 case AKEYCODE_DPAD_UP
:
92 case AKEYCODE_DPAD_RIGHT
:
94 case AKEYCODE_DPAD_DOWN
:
168 case AKEYCODE_VOLUME_DOWN
:
169 return VKEY_VOLUME_DOWN
;
170 case AKEYCODE_VOLUME_UP
:
171 return VKEY_VOLUME_UP
;
172 case AKEYCODE_MEDIA_NEXT
:
173 return VKEY_MEDIA_NEXT_TRACK
;
174 case AKEYCODE_MEDIA_PREVIOUS
:
175 return VKEY_MEDIA_PREV_TRACK
;
176 case AKEYCODE_MEDIA_STOP
:
177 return VKEY_MEDIA_STOP
;
178 case AKEYCODE_MEDIA_PAUSE
:
179 return VKEY_MEDIA_PLAY_PAUSE
;
181 case AKEYCODE_SEMICOLON
:
184 return VKEY_OEM_COMMA
;
186 return VKEY_OEM_MINUS
;
187 case AKEYCODE_EQUALS
:
188 return VKEY_OEM_PLUS
;
189 case AKEYCODE_PERIOD
:
190 return VKEY_OEM_PERIOD
;
193 case AKEYCODE_LEFT_BRACKET
:
195 case AKEYCODE_BACKSLASH
:
197 case AKEYCODE_RIGHT_BRACKET
:
200 case AKEYCODE_VOLUME_MUTE
:
201 return VKEY_VOLUME_MUTE
;
202 case AKEYCODE_ESCAPE
:
204 case AKEYCODE_MEDIA_PLAY
:
205 case AKEYCODE_MEDIA_PLAY_PAUSE
:
206 return VKEY_MEDIA_PLAY_PAUSE
;
207 case AKEYCODE_MOVE_END
:
209 case AKEYCODE_ALT_LEFT
:
211 case AKEYCODE_ALT_RIGHT
:
215 case AKEYCODE_APOSTROPHE
:
217 case AKEYCODE_MEDIA_REWIND
:
219 case AKEYCODE_MEDIA_FAST_FORWARD
:
221 case AKEYCODE_PAGE_UP
:
223 case AKEYCODE_PAGE_DOWN
:
225 case AKEYCODE_FORWARD_DEL
:
227 case AKEYCODE_CTRL_LEFT
:
228 return VKEY_LCONTROL
;
229 case AKEYCODE_CTRL_RIGHT
:
230 return VKEY_RCONTROL
;
231 case AKEYCODE_CAPS_LOCK
:
233 case AKEYCODE_SCROLL_LOCK
:
235 case AKEYCODE_META_LEFT
:
237 case AKEYCODE_META_RIGHT
:
241 case AKEYCODE_INSERT
:
267 case AKEYCODE_NUM_LOCK
:
269 case AKEYCODE_NUMPAD_0
:
271 case AKEYCODE_NUMPAD_1
:
273 case AKEYCODE_NUMPAD_2
:
275 case AKEYCODE_NUMPAD_3
:
277 case AKEYCODE_NUMPAD_4
:
279 case AKEYCODE_NUMPAD_5
:
281 case AKEYCODE_NUMPAD_6
:
283 case AKEYCODE_NUMPAD_7
:
285 case AKEYCODE_NUMPAD_8
:
287 case AKEYCODE_NUMPAD_9
:
289 case AKEYCODE_NUMPAD_DIVIDE
:
291 case AKEYCODE_NUMPAD_MULTIPLY
:
292 return VKEY_MULTIPLY
;
293 case AKEYCODE_NUMPAD_SUBTRACT
:
294 return VKEY_SUBTRACT
;
295 case AKEYCODE_NUMPAD_ADD
:
297 case AKEYCODE_NUMPAD_DOT
:
299 case AKEYCODE_CHANNEL_UP
:
301 case AKEYCODE_CHANNEL_DOWN
: