2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
4 * Copyright (C) 2007 Holger Hans Peter Freyther
5 * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
6 * Copyright (C) 2008, 2009 Google Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // windowsKeyCodeForKeyEvent is copied from platform/gtk/KeyEventGtk.cpp
34 #include "platform/KeyCodeConversion.h"
36 #include "platform/KeyboardCodes.h"
38 #include <gdk/gdkkeysyms.h>
42 int windowsKeyCodeForKeyEvent(unsigned keycode)
46 return VKEY_NUMPAD0; // (60) Numeric keypad 0 key
48 return VKEY_NUMPAD1; // (61) Numeric keypad 1 key
50 return VKEY_NUMPAD2; // (62) Numeric keypad 2 key
52 return VKEY_NUMPAD3; // (63) Numeric keypad 3 key
54 return VKEY_NUMPAD4; // (64) Numeric keypad 4 key
56 return VKEY_NUMPAD5; //(65) Numeric keypad 5 key
58 return VKEY_NUMPAD6; // (66) Numeric keypad 6 key
60 return VKEY_NUMPAD7; // (67) Numeric keypad 7 key
62 return VKEY_NUMPAD8; // (68) Numeric keypad 8 key
64 return VKEY_NUMPAD9; // (69) Numeric keypad 9 key
66 return VKEY_MULTIPLY; // (6A) Multiply key
68 return VKEY_ADD; // (6B) Add key
70 return VKEY_SUBTRACT; // (6D) Subtract key
72 return VKEY_DECIMAL; // (6E) Decimal key
74 return VKEY_DIVIDE; // (6F) Divide key
77 return VKEY_PRIOR; // (21) PAGE UP key
78 case GDK_KP_Page_Down:
79 return VKEY_NEXT; // (22) PAGE DOWN key
81 return VKEY_END; // (23) END key
83 return VKEY_HOME; // (24) HOME key
85 return VKEY_LEFT; // (25) LEFT ARROW key
87 return VKEY_UP; // (26) UP ARROW key
89 return VKEY_RIGHT; // (27) RIGHT ARROW key
91 return VKEY_DOWN; // (28) DOWN ARROW key
93 return VKEY_CLEAR; // (12) CLEAR key
95 return VKEY_INSERT; // (45) INS key
97 return VKEY_DELETE; // (46) DEL key
100 return VKEY_BACK; // (08) BACKSPACE key
101 case GDK_ISO_Left_Tab:
102 case GDK_3270_BackTab:
104 return VKEY_TAB; // (09) TAB key
106 return VKEY_CLEAR; // (0C) CLEAR key
110 return VKEY_RETURN; //(0D) Return key
112 return VKEY_LSHIFT; // (A0) Left SHIFT key
114 return VKEY_RSHIFT; // (A1) Right SHIFT key
116 return VKEY_LCONTROL; // (A2) Left CTRL key
118 return VKEY_RCONTROL; // (A3) Right CTRL key
120 return VKEY_APPS; // (5D) Applications key (Natural keyboard)
123 return VKEY_LMENU; // (A4) Left ALT key
126 case GDK_ISO_Level3_Shift:
127 return VKEY_RMENU; // (A5) Right ALT key
130 return VKEY_PAUSE; // (13) PAUSE key
132 return VKEY_CAPITAL; // (14) CAPS LOCK key
135 return VKEY_KANA; // (15) Input Method Editor (IME) Kana mode
137 return VKEY_HANGUL; // VKEY_HANGUL (15) IME Hangul mode
138 // VKEY_JUNJA (17) IME Junja mode
139 // VKEY_FINAL (18) IME final mode
140 case GDK_Hangul_Hanja:
141 return VKEY_HANJA; // (19) IME Hanja mode
143 return VKEY_KANJI; // (19) IME Kanji mode
145 return VKEY_ESCAPE; // (1B) ESC key
146 // VKEY_CONVERT (1C) IME convert
147 // VKEY_NONCONVERT (1D) IME nonconvert
148 // VKEY_ACCEPT (1E) IME accept
149 // VKEY_MODECHANGE (1F) IME mode change request
151 return VKEY_SPACE; // (20) SPACEBAR
153 return VKEY_PRIOR; // (21) PAGE UP key
155 return VKEY_NEXT; // (22) PAGE DOWN key
157 return VKEY_END; // (23) END key
159 return VKEY_HOME; // (24) HOME key
161 return VKEY_LEFT; // (25) LEFT ARROW key
163 return VKEY_UP; // (26) UP ARROW key
165 return VKEY_RIGHT; // (27) RIGHT ARROW key
167 return VKEY_DOWN; // (28) DOWN ARROW key
169 return VKEY_SELECT; // (29) SELECT key
171 return VKEY_PRINT; // (2A) PRINT key
173 return VKEY_EXECUTE;// (2B) EXECUTE key
175 //case GDK_PrintScreen:
176 // return VKEY_SNAPSHOT; // (2C) PRINT SCREEN key
178 return VKEY_INSERT; // (2D) INS key
180 return VKEY_DELETE; // (2E) DEL key
182 return VKEY_HELP; // (2F) HELP key
185 return VKEY_0; // (30) 0) key
188 return VKEY_1; // (31) 1 ! key
191 return VKEY_2; // (32) 2 & key
194 return VKEY_3; //case '3': case '#';
196 case GDK_dollar: // (34) 4 key '$';
200 return VKEY_5; // (35) 5 key '%'
202 case GDK_asciicircum:
203 return VKEY_6; // (36) 6 key '^'
206 return VKEY_7; // (37) 7 key case '&'
209 return VKEY_8; // (38) 8 key '*'
212 return VKEY_9; // (39) 9 key '('
215 return VKEY_A; // (41) A key case 'a': case 'A': return 0x41;
218 return VKEY_B; // (42) B key case 'b': case 'B': return 0x42;
221 return VKEY_C; // (43) C key case 'c': case 'C': return 0x43;
224 return VKEY_D; // (44) D key case 'd': case 'D': return 0x44;
227 return VKEY_E; // (45) E key case 'e': case 'E': return 0x45;
230 return VKEY_F; // (46) F key case 'f': case 'F': return 0x46;
233 return VKEY_G; // (47) G key case 'g': case 'G': return 0x47;
236 return VKEY_H; // (48) H key case 'h': case 'H': return 0x48;
239 return VKEY_I; // (49) I key case 'i': case 'I': return 0x49;
242 return VKEY_J; // (4A) J key case 'j': case 'J': return 0x4A;
245 return VKEY_K; // (4B) K key case 'k': case 'K': return 0x4B;
248 return VKEY_L; // (4C) L key case 'l': case 'L': return 0x4C;
251 return VKEY_M; // (4D) M key case 'm': case 'M': return 0x4D;
254 return VKEY_N; // (4E) N key case 'n': case 'N': return 0x4E;
257 return VKEY_O; // (4F) O key case 'o': case 'O': return 0x4F;
260 return VKEY_P; // (50) P key case 'p': case 'P': return 0x50;
263 return VKEY_Q; // (51) Q key case 'q': case 'Q': return 0x51;
266 return VKEY_R; // (52) R key case 'r': case 'R': return 0x52;
269 return VKEY_S; // (53) S key case 's': case 'S': return 0x53;
272 return VKEY_T; // (54) T key case 't': case 'T': return 0x54;
275 return VKEY_U; // (55) U key case 'u': case 'U': return 0x55;
278 return VKEY_V; // (56) V key case 'v': case 'V': return 0x56;
281 return VKEY_W; // (57) W key case 'w': case 'W': return 0x57;
284 return VKEY_X; // (58) X key case 'x': case 'X': return 0x58;
287 return VKEY_Y; // (59) Y key case 'y': case 'Y': return 0x59;
290 return VKEY_Z; // (5A) Z key case 'z': case 'Z': return 0x5A;
292 return VKEY_LWIN; // (5B) Left Windows key (Microsoft Natural keyboard)
294 return VKEY_RWIN; // (5C) Right Windows key (Natural keyboard)
295 // VKEY_SLEEP (5F) Computer Sleep key
296 // VKEY_SEPARATOR (6C) Separator key
297 // VKEY_SUBTRACT (6D) Subtract key
298 // VKEY_DECIMAL (6E) Decimal key
299 // VKEY_DIVIDE (6F) Divide key
300 // handled by key code above
303 return VKEY_NUMLOCK; // (90) NUM LOCK key
305 case GDK_Scroll_Lock:
306 return VKEY_SCROLL; // (91) SCROLL LOCK key
308 // VKEY_LSHIFT (A0) Left SHIFT key
309 // VKEY_RSHIFT (A1) Right SHIFT key
310 // VKEY_LCONTROL (A2) Left CONTROL key
311 // VKEY_RCONTROL (A3) Right CONTROL key
312 // VKEY_LMENU (A4) Left MENU key
313 // VKEY_RMENU (A5) Right MENU key
315 return VKEY_BROWSER_BACK; // (A6) Windows 2000/XP: Browser Back key
317 return VKEY_BROWSER_FORWARD; // (A7) Windows 2000/XP: Browser Forward key
319 return VKEY_BROWSER_REFRESH; // (A8) Windows 2000/XP: Browser Refresh key
321 return VKEY_BROWSER_STOP; // (A9) Windows 2000/XP: Browser Stop key
323 return VKEY_BROWSER_SEARCH; // (AA) Windows 2000/XP: Browser Search key
325 return VKEY_BROWSER_FAVORITES; // (AB) Windows 2000/XP: Browser Favorites key
327 return VKEY_BROWSER_HOME; // (AC) Windows 2000/XP: Browser Start and Home key
329 return VKEY_VOLUME_MUTE; // (AD) Windows 2000/XP: Volume Mute key
330 case GDK_AudioLowerVolume:
331 return VKEY_VOLUME_DOWN; // (AE) Windows 2000/XP: Volume Down key
332 case GDK_AudioRaiseVolume:
333 return VKEY_VOLUME_UP; // (AF) Windows 2000/XP: Volume Up key
335 return VKEY_MEDIA_NEXT_TRACK; // (B0) Windows 2000/XP: Next Track key
337 return VKEY_MEDIA_PREV_TRACK; // (B1) Windows 2000/XP: Previous Track key
339 return VKEY_MEDIA_STOP; // (B2) Windows 2000/XP: Stop Media key
341 return VKEY_MEDIA_PLAY_PAUSE; // (B3) Windows 2000/XP: Play/Pause Media key
343 return VKEY_MEDIA_LAUNCH_MAIL; // (B4) Windows 2000/XP: Start Mail key
344 // VKEY_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key
346 return VKEY_MEDIA_LAUNCH_APP1; // (B6) Windows 2000/XP: Start Application 1 key
348 return VKEY_MEDIA_LAUNCH_APP2; // (B7) Windows 2000/XP: Start Application 2 key
350 // VKEY_OEM_1 (BA) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key
353 return VKEY_OEM_1; //case ';': case ':': return 0xBA;
354 // VKEY_OEM_PLUS (BB) Windows 2000/XP: For any country/region, the '+' key
357 return VKEY_OEM_PLUS; //case '=': case '+': return 0xBB;
358 // VKEY_OEM_COMMA (BC) Windows 2000/XP: For any country/region, the ',' key
361 return VKEY_OEM_COMMA; //case ',': case '<': return 0xBC;
362 // VKEY_OEM_MINUS (BD) Windows 2000/XP: For any country/region, the '-' key
365 return VKEY_OEM_MINUS; //case '-': case '_': return 0xBD;
366 // VKEY_OEM_PERIOD (BE) Windows 2000/XP: For any country/region, the '.' key
369 return VKEY_OEM_PERIOD; //case '.': case '>': return 0xBE;
370 // VKEY_OEM_2 (BF) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key
373 return VKEY_OEM_2; //case '/': case '?': return 0xBF;
374 // VKEY_OEM_3 (C0) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key
377 return VKEY_OEM_3; //case '`': case '~': return 0xC0;
378 // VKEY_OEM_4 (DB) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key
379 case GDK_bracketleft:
381 return VKEY_OEM_4; //case '[': case '{': return 0xDB;
382 // VKEY_OEM_5 (DC) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key
385 return VKEY_OEM_5; //case '\\': case '|': return 0xDC;
386 // VKEY_OEM_6 (DD) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key
387 case GDK_bracketright:
389 return VKEY_OEM_6; // case ']': case '}': return 0xDD;
390 // VKEY_OEM_7 (DE) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key
393 return VKEY_OEM_7; // case '\'': case '"': return 0xDE;
394 // VKEY_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard.
395 // VKEY_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard
396 // VKEY_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key
397 // VKEY_PACKET (E7) Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VKEY_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP
398 // VKEY_ATTN (F6) Attn key
399 // VKEY_CRSEL (F7) CrSel key
400 // VKEY_EXSEL (F8) ExSel key
401 // VKEY_EREOF (F9) Erase EOF key
402 // VKEY_PLAY (FA) Play key
403 // VKEY_ZOOM (FB) Zoom key
404 // VKEY_NONAME (FC) Reserved for future use
405 // VKEY_PA1 (FD) PA1 key
406 // VKEY_OEM_CLEAR (FE) Clear key
431 return VKEY_F1 + (keycode - GDK_F1);
437 } // namespace WebCore