Add native event testing to chromeos::EventRewriter unit tests.
[chromium-blink-merge.git] / ui / events / keycodes / keyboard_code_conversion_x.cc
blob8e420ab29193b7c769b2e4b703522db0d48c6302
1 // Copyright (c) 2012 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_x.h"
7 #define XK_3270 // for XK_3270_BackTab
8 #include <X11/keysym.h>
9 #include <X11/Xlib.h>
10 #include <X11/Xutil.h>
11 #include <X11/XF86keysym.h>
13 #include "base/basictypes.h"
14 #include "base/logging.h"
15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "ui/events/keycodes/dom4/keycode_converter.h"
19 namespace ui {
21 // Get an ui::KeyboardCode from an X keyevent
22 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) {
23 // XLookupKeysym does not take into consideration the state of the lock/shift
24 // etc. keys. So it is necessary to use XLookupString instead.
25 KeySym keysym;
26 XLookupString(&xev->xkey, NULL, 0, &keysym, NULL);
27 KeyboardCode keycode = KeyboardCodeFromXKeysym(keysym);
28 if (keycode == VKEY_UNKNOWN) {
29 keysym = DefaultXKeysymFromHardwareKeycode(xev->xkey.keycode);
30 keycode = KeyboardCodeFromXKeysym(keysym);
33 return keycode;
36 KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym) {
37 // TODO(sad): Have |keysym| go through the X map list?
39 switch (keysym) {
40 case XK_BackSpace:
41 return VKEY_BACK;
42 case XK_Delete:
43 case XK_KP_Delete:
44 return VKEY_DELETE;
45 case XK_Tab:
46 case XK_KP_Tab:
47 case XK_ISO_Left_Tab:
48 case XK_3270_BackTab:
49 return VKEY_TAB;
50 case XK_Linefeed:
51 case XK_Return:
52 case XK_KP_Enter:
53 case XK_ISO_Enter:
54 return VKEY_RETURN;
55 case XK_Clear:
56 case XK_KP_Begin: // NumPad 5 without Num Lock, for crosbug.com/29169.
57 return VKEY_CLEAR;
58 case XK_KP_Space:
59 case XK_space:
60 return VKEY_SPACE;
61 case XK_Home:
62 case XK_KP_Home:
63 return VKEY_HOME;
64 case XK_End:
65 case XK_KP_End:
66 return VKEY_END;
67 case XK_Page_Up:
68 case XK_KP_Page_Up: // aka XK_KP_Prior
69 return VKEY_PRIOR;
70 case XK_Page_Down:
71 case XK_KP_Page_Down: // aka XK_KP_Next
72 return VKEY_NEXT;
73 case XK_Left:
74 case XK_KP_Left:
75 return VKEY_LEFT;
76 case XK_Right:
77 case XK_KP_Right:
78 return VKEY_RIGHT;
79 case XK_Down:
80 case XK_KP_Down:
81 return VKEY_DOWN;
82 case XK_Up:
83 case XK_KP_Up:
84 return VKEY_UP;
85 case XK_Escape:
86 return VKEY_ESCAPE;
87 case XK_Kana_Lock:
88 case XK_Kana_Shift:
89 return VKEY_KANA;
90 case XK_Hangul:
91 return VKEY_HANGUL;
92 case XK_Hangul_Hanja:
93 return VKEY_HANJA;
94 case XK_Kanji:
95 return VKEY_KANJI;
96 case XK_Henkan:
97 return VKEY_CONVERT;
98 case XK_Muhenkan:
99 return VKEY_NONCONVERT;
100 case XK_Zenkaku_Hankaku:
101 return VKEY_DBE_DBCSCHAR;
102 case XK_A:
103 case XK_a:
104 return VKEY_A;
105 case XK_B:
106 case XK_b:
107 return VKEY_B;
108 case XK_C:
109 case XK_c:
110 return VKEY_C;
111 case XK_D:
112 case XK_d:
113 return VKEY_D;
114 case XK_E:
115 case XK_e:
116 return VKEY_E;
117 case XK_F:
118 case XK_f:
119 return VKEY_F;
120 case XK_G:
121 case XK_g:
122 return VKEY_G;
123 case XK_H:
124 case XK_h:
125 return VKEY_H;
126 case XK_I:
127 case XK_i:
128 return VKEY_I;
129 case XK_J:
130 case XK_j:
131 return VKEY_J;
132 case XK_K:
133 case XK_k:
134 return VKEY_K;
135 case XK_L:
136 case XK_l:
137 return VKEY_L;
138 case XK_M:
139 case XK_m:
140 return VKEY_M;
141 case XK_N:
142 case XK_n:
143 return VKEY_N;
144 case XK_O:
145 case XK_o:
146 return VKEY_O;
147 case XK_P:
148 case XK_p:
149 return VKEY_P;
150 case XK_Q:
151 case XK_q:
152 return VKEY_Q;
153 case XK_R:
154 case XK_r:
155 return VKEY_R;
156 case XK_S:
157 case XK_s:
158 return VKEY_S;
159 case XK_T:
160 case XK_t:
161 return VKEY_T;
162 case XK_U:
163 case XK_u:
164 return VKEY_U;
165 case XK_V:
166 case XK_v:
167 return VKEY_V;
168 case XK_W:
169 case XK_w:
170 return VKEY_W;
171 case XK_X:
172 case XK_x:
173 return VKEY_X;
174 case XK_Y:
175 case XK_y:
176 return VKEY_Y;
177 case XK_Z:
178 case XK_z:
179 return VKEY_Z;
181 case XK_0:
182 case XK_1:
183 case XK_2:
184 case XK_3:
185 case XK_4:
186 case XK_5:
187 case XK_6:
188 case XK_7:
189 case XK_8:
190 case XK_9:
191 return static_cast<KeyboardCode>(VKEY_0 + (keysym - XK_0));
193 case XK_parenright:
194 return VKEY_0;
195 case XK_exclam:
196 return VKEY_1;
197 case XK_at:
198 return VKEY_2;
199 case XK_numbersign:
200 return VKEY_3;
201 case XK_dollar:
202 return VKEY_4;
203 case XK_percent:
204 return VKEY_5;
205 case XK_asciicircum:
206 return VKEY_6;
207 case XK_ampersand:
208 return VKEY_7;
209 case XK_asterisk:
210 return VKEY_8;
211 case XK_parenleft:
212 return VKEY_9;
214 case XK_KP_0:
215 case XK_KP_1:
216 case XK_KP_2:
217 case XK_KP_3:
218 case XK_KP_4:
219 case XK_KP_5:
220 case XK_KP_6:
221 case XK_KP_7:
222 case XK_KP_8:
223 case XK_KP_9:
224 return static_cast<KeyboardCode>(VKEY_NUMPAD0 + (keysym - XK_KP_0));
226 case XK_multiply:
227 case XK_KP_Multiply:
228 return VKEY_MULTIPLY;
229 case XK_KP_Add:
230 return VKEY_ADD;
231 case XK_KP_Separator:
232 return VKEY_SEPARATOR;
233 case XK_KP_Subtract:
234 return VKEY_SUBTRACT;
235 case XK_KP_Decimal:
236 return VKEY_DECIMAL;
237 case XK_KP_Divide:
238 return VKEY_DIVIDE;
239 case XK_KP_Equal:
240 case XK_equal:
241 case XK_plus:
242 return VKEY_OEM_PLUS;
243 case XK_comma:
244 case XK_less:
245 return VKEY_OEM_COMMA;
246 case XK_minus:
247 case XK_underscore:
248 return VKEY_OEM_MINUS;
249 case XK_greater:
250 case XK_period:
251 return VKEY_OEM_PERIOD;
252 case XK_colon:
253 case XK_semicolon:
254 return VKEY_OEM_1;
255 case XK_question:
256 case XK_slash:
257 return VKEY_OEM_2;
258 case XK_asciitilde:
259 case XK_quoteleft:
260 return VKEY_OEM_3;
261 case XK_bracketleft:
262 case XK_braceleft:
263 return VKEY_OEM_4;
264 case XK_backslash:
265 case XK_bar:
266 return VKEY_OEM_5;
267 case XK_bracketright:
268 case XK_braceright:
269 return VKEY_OEM_6;
270 case XK_quoteright:
271 case XK_quotedbl:
272 return VKEY_OEM_7;
273 case XK_ISO_Level5_Shift:
274 return VKEY_OEM_8;
275 case XK_Shift_L:
276 case XK_Shift_R:
277 return VKEY_SHIFT;
278 case XK_Control_L:
279 case XK_Control_R:
280 return VKEY_CONTROL;
281 case XK_Meta_L:
282 case XK_Meta_R:
283 case XK_Alt_L:
284 case XK_Alt_R:
285 return VKEY_MENU;
286 case XK_ISO_Level3_Shift:
287 return VKEY_ALTGR;
288 case XK_Multi_key:
289 return VKEY_COMPOSE;
290 case XK_Pause:
291 return VKEY_PAUSE;
292 case XK_Caps_Lock:
293 return VKEY_CAPITAL;
294 case XK_Num_Lock:
295 return VKEY_NUMLOCK;
296 case XK_Scroll_Lock:
297 return VKEY_SCROLL;
298 case XK_Select:
299 return VKEY_SELECT;
300 case XK_Print:
301 return VKEY_PRINT;
302 case XK_Execute:
303 return VKEY_EXECUTE;
304 case XK_Insert:
305 case XK_KP_Insert:
306 return VKEY_INSERT;
307 case XK_Help:
308 return VKEY_HELP;
309 case XK_Super_L:
310 return VKEY_LWIN;
311 case XK_Super_R:
312 return VKEY_RWIN;
313 case XK_Menu:
314 return VKEY_APPS;
315 case XK_F1:
316 case XK_F2:
317 case XK_F3:
318 case XK_F4:
319 case XK_F5:
320 case XK_F6:
321 case XK_F7:
322 case XK_F8:
323 case XK_F9:
324 case XK_F10:
325 case XK_F11:
326 case XK_F12:
327 case XK_F13:
328 case XK_F14:
329 case XK_F15:
330 case XK_F16:
331 case XK_F17:
332 case XK_F18:
333 case XK_F19:
334 case XK_F20:
335 case XK_F21:
336 case XK_F22:
337 case XK_F23:
338 case XK_F24:
339 return static_cast<KeyboardCode>(VKEY_F1 + (keysym - XK_F1));
340 case XK_KP_F1:
341 case XK_KP_F2:
342 case XK_KP_F3:
343 case XK_KP_F4:
344 return static_cast<KeyboardCode>(VKEY_F1 + (keysym - XK_KP_F1));
346 case XK_guillemotleft:
347 case XK_guillemotright:
348 case XK_degree:
349 // In the case of canadian multilingual keyboard layout, VKEY_OEM_102 is
350 // assigned to ugrave key.
351 case XK_ugrave:
352 case XK_Ugrave:
353 case XK_brokenbar:
354 return VKEY_OEM_102; // international backslash key in 102 keyboard.
356 // When evdev is in use, /usr/share/X11/xkb/symbols/inet maps F13-18 keys
357 // to the special XF86XK symbols to support Microsoft Ergonomic keyboards:
358 // https://bugs.freedesktop.org/show_bug.cgi?id=5783
359 // In Chrome, we map these X key symbols back to F13-18 since we don't have
360 // VKEYs for these XF86XK symbols.
361 case XF86XK_Tools:
362 return VKEY_F13;
363 case XF86XK_Launch5:
364 return VKEY_F14;
365 case XF86XK_Launch6:
366 return VKEY_F15;
367 case XF86XK_Launch7:
368 return VKEY_F16;
369 case XF86XK_Launch8:
370 return VKEY_F17;
371 case XF86XK_Launch9:
372 return VKEY_F18;
374 // For supporting multimedia buttons on a USB keyboard.
375 case XF86XK_Back:
376 return VKEY_BROWSER_BACK;
377 case XF86XK_Forward:
378 return VKEY_BROWSER_FORWARD;
379 case XF86XK_Reload:
380 return VKEY_BROWSER_REFRESH;
381 case XF86XK_Stop:
382 return VKEY_BROWSER_STOP;
383 case XF86XK_Search:
384 return VKEY_BROWSER_SEARCH;
385 case XF86XK_Favorites:
386 return VKEY_BROWSER_FAVORITES;
387 case XF86XK_HomePage:
388 return VKEY_BROWSER_HOME;
389 case XF86XK_AudioMute:
390 return VKEY_VOLUME_MUTE;
391 case XF86XK_AudioLowerVolume:
392 return VKEY_VOLUME_DOWN;
393 case XF86XK_AudioRaiseVolume:
394 return VKEY_VOLUME_UP;
395 case XF86XK_AudioNext:
396 return VKEY_MEDIA_NEXT_TRACK;
397 case XF86XK_AudioPrev:
398 return VKEY_MEDIA_PREV_TRACK;
399 case XF86XK_AudioStop:
400 return VKEY_MEDIA_STOP;
401 case XF86XK_AudioPlay:
402 return VKEY_MEDIA_PLAY_PAUSE;
403 case XF86XK_Mail:
404 return VKEY_MEDIA_LAUNCH_MAIL;
405 case XF86XK_LaunchA: // F3 on an Apple keyboard.
406 return VKEY_MEDIA_LAUNCH_APP1;
407 case XF86XK_LaunchB: // F4 on an Apple keyboard.
408 case XF86XK_Calculator:
409 return VKEY_MEDIA_LAUNCH_APP2;
410 case XF86XK_WLAN:
411 return VKEY_WLAN;
412 case XF86XK_PowerOff:
413 return VKEY_POWER;
414 case XF86XK_MonBrightnessDown:
415 return VKEY_BRIGHTNESS_DOWN;
416 case XF86XK_MonBrightnessUp:
417 return VKEY_BRIGHTNESS_UP;
418 case XF86XK_KbdBrightnessDown:
419 return VKEY_KBD_BRIGHTNESS_DOWN;
420 case XF86XK_KbdBrightnessUp:
421 return VKEY_KBD_BRIGHTNESS_UP;
423 // TODO(sad): some keycodes are still missing.
425 DLOG(WARNING) << "Unknown keysym: " << base::StringPrintf("0x%x", keysym);
426 return VKEY_UNKNOWN;
429 const char* CodeFromXEvent(XEvent* xev) {
430 return KeycodeConverter::GetInstance()->NativeKeycodeToCode(
431 xev->xkey.keycode);
434 uint16 GetCharacterFromXEvent(XEvent* xev) {
435 char buf[6];
436 int bytes_written = XLookupString(&xev->xkey, buf, 6, NULL, NULL);
437 DCHECK_LE(bytes_written, 6);
439 base::string16 result;
440 return (bytes_written > 0 && base::UTF8ToUTF16(buf, bytes_written, &result) &&
441 result.length() == 1) ? result[0] : 0;
444 unsigned int DefaultXKeysymFromHardwareKeycode(unsigned int hardware_code) {
445 // This function assumes that X11 is using evdev-based keycodes.
446 static const unsigned int kHardwareKeycodeMap[] = {
447 // This table covers the core 105-key keyboard.
448 0, // 0x00:
449 0, // 0x01:
450 0, // 0x02:
451 0, // 0x03:
452 0, // 0x04:
453 0, // 0x05:
454 0, // 0x06:
455 0, // XKB evdev (XKB - 8) X KeySym
456 0, // === =============== ======
457 XK_Escape, // 0x09: KEY_ESC Escape
458 XK_1, // 0x0A: KEY_1 1
459 XK_2, // 0x0B: KEY_2 2
460 XK_3, // 0x0C: KEY_3 3
461 XK_4, // 0x0D: KEY_4 4
462 XK_5, // 0x0E: KEY_5 5
463 XK_6, // 0x0F: KEY_6 6
464 XK_7, // 0x10: KEY_7 7
465 XK_8, // 0x11: KEY_8 8
466 XK_9, // 0x12: KEY_9 9
467 XK_0, // 0x13: KEY_0 0
468 XK_minus, // 0x14: KEY_MINUS minus
469 XK_equal, // 0x15: KEY_EQUAL equal
470 XK_BackSpace, // 0x16: KEY_BACKSPACE BackSpace
471 XK_Tab, // 0x17: KEY_TAB Tab
472 XK_q, // 0x18: KEY_Q q
473 XK_w, // 0x19: KEY_W w
474 XK_e, // 0x1A: KEY_E e
475 XK_r, // 0x1B: KEY_R r
476 XK_t, // 0x1C: KEY_T t
477 XK_y, // 0x1D: KEY_Y y
478 XK_u, // 0x1E: KEY_U u
479 XK_i, // 0x1F: KEY_I i
480 XK_o, // 0x20: KEY_O o
481 XK_p, // 0x21: KEY_P p
482 XK_bracketleft, // 0x22: KEY_LEFTBRACE bracketleft
483 XK_bracketright, // 0x23: KEY_RIGHTBRACE bracketright
484 XK_Return, // 0x24: KEY_ENTER Return
485 XK_Control_L, // 0x25: KEY_LEFTCTRL Control_L
486 XK_a, // 0x26: KEY_A a
487 XK_s, // 0x27: KEY_S s
488 XK_d, // 0x28: KEY_D d
489 XK_f, // 0x29: KEY_F f
490 XK_g, // 0x2A: KEY_G g
491 XK_h, // 0x2B: KEY_H h
492 XK_j, // 0x2C: KEY_J j
493 XK_k, // 0x2D: KEY_K k
494 XK_l, // 0x2E: KEY_L l
495 XK_semicolon, // 0x2F: KEY_SEMICOLON semicolon
496 XK_apostrophe, // 0x30: KEY_APOSTROPHE apostrophe
497 XK_grave, // 0x31: KEY_GRAVE grave
498 XK_Shift_L, // 0x32: KEY_LEFTSHIFT Shift_L
499 XK_backslash, // 0x33: KEY_BACKSLASH backslash
500 XK_z, // 0x34: KEY_Z z
501 XK_x, // 0x35: KEY_X x
502 XK_c, // 0x36: KEY_C c
503 XK_v, // 0x37: KEY_V v
504 XK_b, // 0x38: KEY_B b
505 XK_n, // 0x39: KEY_N n
506 XK_m, // 0x3A: KEY_M m
507 XK_comma, // 0x3B: KEY_COMMA comma
508 XK_period, // 0x3C: KEY_DOT period
509 XK_slash, // 0x3D: KEY_SLASH slash
510 XK_Shift_R, // 0x3E: KEY_RIGHTSHIFT Shift_R
511 0, // 0x3F: KEY_KPASTERISK KP_Multiply
512 XK_Alt_L, // 0x40: KEY_LEFTALT Alt_L
513 XK_space, // 0x41: KEY_SPACE space
514 XK_Caps_Lock, // 0x42: KEY_CAPSLOCK Caps_Lock
515 XK_F1, // 0x43: KEY_F1 F1
516 XK_F2, // 0x44: KEY_F2 F2
517 XK_F3, // 0x45: KEY_F3 F3
518 XK_F4, // 0x46: KEY_F4 F4
519 XK_F5, // 0x47: KEY_F5 F5
520 XK_F6, // 0x48: KEY_F6 F6
521 XK_F7, // 0x49: KEY_F7 F7
522 XK_F8, // 0x4A: KEY_F8 F8
523 XK_F9, // 0x4B: KEY_F9 F9
524 XK_F10, // 0x4C: KEY_F10 F10
525 XK_Num_Lock, // 0x4D: KEY_NUMLOCK Num_Lock
526 XK_Scroll_Lock, // 0x4E: KEY_SCROLLLOCK Scroll_Lock
527 XK_KP_7, // 0x4F: KEY_KP7 KP_7
528 XK_KP_8, // 0x50: KEY_KP8 KP_8
529 XK_KP_9, // 0x51: KEY_KP9 KP_9
530 XK_KP_Subtract, // 0x52: KEY_KPMINUS KP_Subtract
531 XK_KP_4, // 0x53: KEY_KP4 KP_4
532 XK_KP_5, // 0x54: KEY_KP5 KP_5
533 XK_KP_6, // 0x55: KEY_KP6 KP_6
534 XK_KP_Add, // 0x56: KEY_KPPLUS KP_Add
535 XK_KP_1, // 0x57: KEY_KP1 KP_1
536 XK_KP_2, // 0x58: KEY_KP2 KP_2
537 XK_KP_3, // 0x59: KEY_KP3 KP_3
538 XK_KP_0, // 0x5A: KEY_KP0 KP_0
539 XK_KP_Decimal, // 0x5B: KEY_KPDOT KP_Decimal
540 0, // 0x5C:
541 XK_Zenkaku_Hankaku, // 0x5D: KEY_ZENKAKUHANKAKU Zenkaku_Hankaku
542 XK_backslash, // 0x5E: KEY_102ND backslash
543 XK_F11, // 0x5F: KEY_F11 F11
544 XK_F12, // 0x60: KEY_F12 F12
545 XK_Romaji, // 0x61: KEY_RO Romaji
546 XK_Katakana, // 0x62: KEY_KATAKANA Katakana
547 XK_Hiragana, // 0x63: KEY_HIRAGANA Hiragana
548 XK_Henkan, // 0x64: KEY_HENKAN Henkan
549 XK_Hiragana_Katakana, // 0x65: KEY_KATAKANAHIRAGANA Hiragana_Katakana
550 XK_Muhenkan, // 0x66: KEY_MUHENKAN Muhenkan
551 XK_KP_Separator, // 0x67: KEY_KPJPCOMMA KP_Separator
552 XK_KP_Enter, // 0x68: KEY_KPENTER KP_Enter
553 XK_Control_R, // 0x69: KEY_RIGHTCTRL Control_R
554 XK_KP_Divide, // 0x6A: KEY_KPSLASH KP_Divide
555 XK_Print, // 0x6B: KEY_SYSRQ Print
556 XK_Alt_R, // 0x6C: KEY_RIGHTALT Alt_R
557 XK_Linefeed, // 0x6D: KEY_LINEFEED Linefeed
558 XK_Home, // 0x6E: KEY_HOME Home
559 XK_Up, // 0x6F: KEY_UP Up
560 XK_Page_Up, // 0x70: KEY_PAGEUP Page_Up
561 XK_Left, // 0x71: KEY_LEFT Left
562 XK_Right, // 0x72: KEY_RIGHT Right
563 XK_End, // 0x73: KEY_END End
564 XK_Down, // 0x74: KEY_DOWN Down
565 XK_Page_Down, // 0x75: KEY_PAGEDOWN Page_Down
566 XK_Insert, // 0x76: KEY_INSERT Insert
567 XK_Delete, // 0x77: KEY_DELETE Delete
568 0, // 0x78: KEY_MACRO
569 XF86XK_AudioMute, // 0x79: KEY_MUTE XF86AudioMute
570 XF86XK_AudioLowerVolume, // 0x7A: KEY_VOLUMEDOWN XF86AudioLowerVolume
571 XF86XK_AudioRaiseVolume, // 0x7B: KEY_VOLUMEUP XF86AudioRaiseVolume
572 XF86XK_PowerOff, // 0x7C: KEY_POWER XF86PowerOff
573 XK_KP_Equal, // 0x7D: KEY_KPEQUAL KP_Equal
574 XK_plusminus, // 0x7E: KEY_KPPLUSMINUS plusminus
575 XK_Pause, // 0x7F: KEY_PAUSE Pause
576 XF86XK_LaunchA, // 0x80: KEY_SCALE XF86LaunchA
577 XK_KP_Decimal, // 0x81: KEY_KPCOMMA KP_Decimal
578 XK_Hangul, // 0x82: KEY_HANGUEL Hangul
579 XK_Hangul_Hanja, // 0x83: KEY_HANJA Hangul_Hanja
580 XK_yen, // 0x84: KEY_YEN yen
581 XK_Super_L, // 0x85: KEY_LEFTMETA Super_L
582 XK_Super_R, // 0x86: KEY_RIGHTMETA Super_R
583 XK_Menu, // 0x87: KEY_COMPOSE Menu
586 if (hardware_code >= arraysize(kHardwareKeycodeMap)) {
587 // Additional keycodes used by the Chrome OS top row special function keys.
588 switch (hardware_code) {
589 case 0xA6: // KEY_BACK
590 return XF86XK_Back;
591 case 0xA7: // KEY_FORWARD
592 return XF86XK_Forward;
593 case 0xB5: // KEY_REFRESH
594 return XF86XK_Reload;
595 case 0xD4: // KEY_DASHBOARD
596 return XF86XK_LaunchB;
597 case 0xE8: // KEY_BRIGHTNESSDOWN
598 return XF86XK_MonBrightnessDown;
599 case 0xE9: // KEY_BRIGHTNESSUP
600 return XF86XK_MonBrightnessUp;
602 return 0;
604 return kHardwareKeycodeMap[hardware_code];
607 // TODO(jcampan): this method might be incomplete.
608 int XKeysymForWindowsKeyCode(KeyboardCode keycode, bool shift) {
609 switch (keycode) {
610 case VKEY_NUMPAD0:
611 return XK_KP_0;
612 case VKEY_NUMPAD1:
613 return XK_KP_1;
614 case VKEY_NUMPAD2:
615 return XK_KP_2;
616 case VKEY_NUMPAD3:
617 return XK_KP_3;
618 case VKEY_NUMPAD4:
619 return XK_KP_4;
620 case VKEY_NUMPAD5:
621 return XK_KP_5;
622 case VKEY_NUMPAD6:
623 return XK_KP_6;
624 case VKEY_NUMPAD7:
625 return XK_KP_7;
626 case VKEY_NUMPAD8:
627 return XK_KP_8;
628 case VKEY_NUMPAD9:
629 return XK_KP_9;
630 case VKEY_MULTIPLY:
631 return XK_KP_Multiply;
632 case VKEY_ADD:
633 return XK_KP_Add;
634 case VKEY_SUBTRACT:
635 return XK_KP_Subtract;
636 case VKEY_DECIMAL:
637 return XK_KP_Decimal;
638 case VKEY_DIVIDE:
639 return XK_KP_Divide;
641 case VKEY_BACK:
642 return XK_BackSpace;
643 case VKEY_TAB:
644 return shift ? XK_ISO_Left_Tab : XK_Tab;
645 case VKEY_CLEAR:
646 return XK_Clear;
647 case VKEY_RETURN:
648 return XK_Return;
649 case VKEY_SHIFT:
650 return XK_Shift_L;
651 case VKEY_CONTROL:
652 return XK_Control_L;
653 case VKEY_MENU:
654 return XK_Alt_L;
655 case VKEY_APPS:
656 return XK_Menu;
657 case VKEY_ALTGR:
658 return XK_ISO_Level3_Shift;
659 case VKEY_COMPOSE:
660 return XK_Multi_key;
662 case VKEY_PAUSE:
663 return XK_Pause;
664 case VKEY_CAPITAL:
665 return XK_Caps_Lock;
666 case VKEY_KANA:
667 return XK_Kana_Lock;
668 case VKEY_HANJA:
669 return XK_Hangul_Hanja;
670 case VKEY_CONVERT:
671 return XK_Henkan;
672 case VKEY_NONCONVERT:
673 return XK_Muhenkan;
674 case VKEY_DBE_SBCSCHAR:
675 return XK_Zenkaku_Hankaku;
676 case VKEY_DBE_DBCSCHAR:
677 return XK_Zenkaku_Hankaku;
678 case VKEY_ESCAPE:
679 return XK_Escape;
680 case VKEY_SPACE:
681 return XK_space;
682 case VKEY_PRIOR:
683 return XK_Page_Up;
684 case VKEY_NEXT:
685 return XK_Page_Down;
686 case VKEY_END:
687 return XK_End;
688 case VKEY_HOME:
689 return XK_Home;
690 case VKEY_LEFT:
691 return XK_Left;
692 case VKEY_UP:
693 return XK_Up;
694 case VKEY_RIGHT:
695 return XK_Right;
696 case VKEY_DOWN:
697 return XK_Down;
698 case VKEY_SELECT:
699 return XK_Select;
700 case VKEY_PRINT:
701 return XK_Print;
702 case VKEY_EXECUTE:
703 return XK_Execute;
704 case VKEY_INSERT:
705 return XK_Insert;
706 case VKEY_DELETE:
707 return XK_Delete;
708 case VKEY_HELP:
709 return XK_Help;
710 case VKEY_0:
711 return shift ? XK_parenright : XK_0;
712 case VKEY_1:
713 return shift ? XK_exclam : XK_1;
714 case VKEY_2:
715 return shift ? XK_at : XK_2;
716 case VKEY_3:
717 return shift ? XK_numbersign : XK_3;
718 case VKEY_4:
719 return shift ? XK_dollar : XK_4;
720 case VKEY_5:
721 return shift ? XK_percent : XK_5;
722 case VKEY_6:
723 return shift ? XK_asciicircum : XK_6;
724 case VKEY_7:
725 return shift ? XK_ampersand : XK_7;
726 case VKEY_8:
727 return shift ? XK_asterisk : XK_8;
728 case VKEY_9:
729 return shift ? XK_parenleft : XK_9;
731 case VKEY_A:
732 case VKEY_B:
733 case VKEY_C:
734 case VKEY_D:
735 case VKEY_E:
736 case VKEY_F:
737 case VKEY_G:
738 case VKEY_H:
739 case VKEY_I:
740 case VKEY_J:
741 case VKEY_K:
742 case VKEY_L:
743 case VKEY_M:
744 case VKEY_N:
745 case VKEY_O:
746 case VKEY_P:
747 case VKEY_Q:
748 case VKEY_R:
749 case VKEY_S:
750 case VKEY_T:
751 case VKEY_U:
752 case VKEY_V:
753 case VKEY_W:
754 case VKEY_X:
755 case VKEY_Y:
756 case VKEY_Z:
757 return (shift ? XK_A : XK_a) + (keycode - VKEY_A);
759 case VKEY_LWIN:
760 return XK_Super_L;
761 case VKEY_RWIN:
762 return XK_Super_R;
764 case VKEY_NUMLOCK:
765 return XK_Num_Lock;
767 case VKEY_SCROLL:
768 return XK_Scroll_Lock;
770 case VKEY_OEM_1:
771 return shift ? XK_colon : XK_semicolon;
772 case VKEY_OEM_PLUS:
773 return shift ? XK_plus : XK_equal;
774 case VKEY_OEM_COMMA:
775 return shift ? XK_less : XK_comma;
776 case VKEY_OEM_MINUS:
777 return shift ? XK_underscore : XK_minus;
778 case VKEY_OEM_PERIOD:
779 return shift ? XK_greater : XK_period;
780 case VKEY_OEM_2:
781 return shift ? XK_question : XK_slash;
782 case VKEY_OEM_3:
783 return shift ? XK_asciitilde : XK_quoteleft;
784 case VKEY_OEM_4:
785 return shift ? XK_braceleft : XK_bracketleft;
786 case VKEY_OEM_5:
787 return shift ? XK_bar : XK_backslash;
788 case VKEY_OEM_6:
789 return shift ? XK_braceright : XK_bracketright;
790 case VKEY_OEM_7:
791 return shift ? XK_quotedbl : XK_quoteright;
792 case VKEY_OEM_8:
793 return XK_ISO_Level5_Shift;
794 case VKEY_OEM_102:
795 return shift ? XK_guillemotleft : XK_guillemotright;
797 case VKEY_F1:
798 case VKEY_F2:
799 case VKEY_F3:
800 case VKEY_F4:
801 case VKEY_F5:
802 case VKEY_F6:
803 case VKEY_F7:
804 case VKEY_F8:
805 case VKEY_F9:
806 case VKEY_F10:
807 case VKEY_F11:
808 case VKEY_F12:
809 case VKEY_F13:
810 case VKEY_F14:
811 case VKEY_F15:
812 case VKEY_F16:
813 case VKEY_F17:
814 case VKEY_F18:
815 case VKEY_F19:
816 case VKEY_F20:
817 case VKEY_F21:
818 case VKEY_F22:
819 case VKEY_F23:
820 case VKEY_F24:
821 return XK_F1 + (keycode - VKEY_F1);
823 case VKEY_BROWSER_BACK:
824 return XF86XK_Back;
825 case VKEY_BROWSER_FORWARD:
826 return XF86XK_Forward;
827 case VKEY_BROWSER_REFRESH:
828 return XF86XK_Reload;
829 case VKEY_BROWSER_STOP:
830 return XF86XK_Stop;
831 case VKEY_BROWSER_SEARCH:
832 return XF86XK_Search;
833 case VKEY_BROWSER_FAVORITES:
834 return XF86XK_Favorites;
835 case VKEY_BROWSER_HOME:
836 return XF86XK_HomePage;
837 case VKEY_VOLUME_MUTE:
838 return XF86XK_AudioMute;
839 case VKEY_VOLUME_DOWN:
840 return XF86XK_AudioLowerVolume;
841 case VKEY_VOLUME_UP:
842 return XF86XK_AudioRaiseVolume;
843 case VKEY_MEDIA_NEXT_TRACK:
844 return XF86XK_AudioNext;
845 case VKEY_MEDIA_PREV_TRACK:
846 return XF86XK_AudioPrev;
847 case VKEY_MEDIA_STOP:
848 return XF86XK_AudioStop;
849 case VKEY_MEDIA_PLAY_PAUSE:
850 return XF86XK_AudioPlay;
851 case VKEY_MEDIA_LAUNCH_MAIL:
852 return XF86XK_Mail;
853 case VKEY_MEDIA_LAUNCH_APP1:
854 return XF86XK_LaunchA;
855 case VKEY_MEDIA_LAUNCH_APP2:
856 return XF86XK_LaunchB;
857 case VKEY_WLAN:
858 return XF86XK_WLAN;
859 case VKEY_POWER:
860 return XF86XK_PowerOff;
861 case VKEY_BRIGHTNESS_DOWN:
862 return XF86XK_MonBrightnessDown;
863 case VKEY_BRIGHTNESS_UP:
864 return XF86XK_MonBrightnessUp;
865 case VKEY_KBD_BRIGHTNESS_DOWN:
866 return XF86XK_KbdBrightnessDown;
867 case VKEY_KBD_BRIGHTNESS_UP:
868 return XF86XK_KbdBrightnessUp;
870 default:
871 LOG(WARNING) << "Unknown keycode:" << keycode;
872 return 0;
876 } // namespace ui