1 /* 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 3 * Copyright (C) 2006 Michael Emmel mike.emmel (at) 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. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 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. 16 * 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. 28 */ 29 30 // windowsKeyCodeForKeyEvent is copied from platform/gtk/KeyEventGtk.cpp 31 32 #include "config.h" 33 #include "KeyCodeConversion.h" 34 35 #include "KeyboardCodes.h" 36 37 #include <gdk/gdkkeysyms.h> 38 39 namespace WebCore { 40 41 int windowsKeyCodeForKeyEvent(unsigned keycode) 42 { 43 switch (keycode) { 44 case GDK_KP_0: 45 return VKEY_NUMPAD0; // (60) Numeric keypad 0 key 46 case GDK_KP_1: 47 return VKEY_NUMPAD1; // (61) Numeric keypad 1 key 48 case GDK_KP_2: 49 return VKEY_NUMPAD2; // (62) Numeric keypad 2 key 50 case GDK_KP_3: 51 return VKEY_NUMPAD3; // (63) Numeric keypad 3 key 52 case GDK_KP_4: 53 return VKEY_NUMPAD4; // (64) Numeric keypad 4 key 54 case GDK_KP_5: 55 return VKEY_NUMPAD5; //(65) Numeric keypad 5 key 56 case GDK_KP_6: 57 return VKEY_NUMPAD6; // (66) Numeric keypad 6 key 58 case GDK_KP_7: 59 return VKEY_NUMPAD7; // (67) Numeric keypad 7 key 60 case GDK_KP_8: 61 return VKEY_NUMPAD8; // (68) Numeric keypad 8 key 62 case GDK_KP_9: 63 return VKEY_NUMPAD9; // (69) Numeric keypad 9 key 64 case GDK_KP_Multiply: 65 return VKEY_MULTIPLY; // (6A) Multiply key 66 case GDK_KP_Add: 67 return VKEY_ADD; // (6B) Add key 68 case GDK_KP_Subtract: 69 return VKEY_SUBTRACT; // (6D) Subtract key 70 case GDK_KP_Decimal: 71 return VKEY_DECIMAL; // (6E) Decimal key 72 case GDK_KP_Divide: 73 return VKEY_DIVIDE; // (6F) Divide key 74 75 case GDK_KP_Page_Up: 76 return VKEY_PRIOR; // (21) PAGE UP key 77 case GDK_KP_Page_Down: 78 return VKEY_NEXT; // (22) PAGE DOWN key 79 case GDK_KP_End: 80 return VKEY_END; // (23) END key 81 case GDK_KP_Home: 82 return VKEY_HOME; // (24) HOME key 83 case GDK_KP_Left: 84 return VKEY_LEFT; // (25) LEFT ARROW key 85 case GDK_KP_Up: 86 return VKEY_UP; // (26) UP ARROW key 87 case GDK_KP_Right: 88 return VKEY_RIGHT; // (27) RIGHT ARROW key 89 case GDK_KP_Down: 90 return VKEY_DOWN; // (28) DOWN ARROW key 91 92 case GDK_BackSpace: 93 return VKEY_BACK; // (08) BACKSPACE key 94 case GDK_ISO_Left_Tab: 95 case GDK_3270_BackTab: 96 case GDK_Tab: 97 return VKEY_TAB; // (09) TAB key 98 case GDK_Clear: 99 return VKEY_CLEAR; // (0C) CLEAR key 100 case GDK_ISO_Enter: 101 case GDK_KP_Enter: 102 case GDK_Return: 103 return VKEY_RETURN; //(0D) Return key 104 case GDK_Shift_L: 105 case GDK_Shift_R: 106 return VKEY_SHIFT; // (10) SHIFT key 107 case GDK_Control_L: 108 case GDK_Control_R: 109 return VKEY_CONTROL; // (11) CTRL key 110 case GDK_Menu: 111 return VKEY_APPS; // (5D) Applications key (Natural keyboard) 112 case GDK_Alt_L: 113 case GDK_Alt_R: 114 return VKEY_MENU; // (12) ALT key 115 116 case GDK_Pause: 117 return VKEY_PAUSE; // (13) PAUSE key 118 case GDK_Caps_Lock: 119 return VKEY_CAPITAL; // (14) CAPS LOCK key 120 case GDK_Kana_Lock: 121 case GDK_Kana_Shift: 122 return VKEY_KANA; // (15) Input Method Editor (IME) Kana mode 123 case GDK_Hangul: 124 return VKEY_HANGUL; // VKEY_HANGUL (15) IME Hangul mode 125 // VKEY_JUNJA (17) IME Junja mode 126 // VKEY_FINAL (18) IME final mode 127 case GDK_Hangul_Hanja: 128 return VKEY_HANJA; // (19) IME Hanja mode 129 case GDK_Kanji: 130 return VKEY_KANJI; // (19) IME Kanji mode 131 case GDK_Escape: 132 return VKEY_ESCAPE; // (1B) ESC key 133 // VKEY_CONVERT (1C) IME convert 134 // VKEY_NONCONVERT (1D) IME nonconvert 135 // VKEY_ACCEPT (1E) IME accept 136 // VKEY_MODECHANGE (1F) IME mode change request 137 case GDK_space: 138 return VKEY_SPACE; // (20) SPACEBAR 139 case GDK_Page_Up: 140 return VKEY_PRIOR; // (21) PAGE UP key 141 case GDK_Page_Down: 142 return VKEY_NEXT; // (22) PAGE DOWN key 143 case GDK_End: 144 return VKEY_END; // (23) END key 145 case GDK_Home: 146 return VKEY_HOME; // (24) HOME key 147 case GDK_Left: 148 return VKEY_LEFT; // (25) LEFT ARROW key 149 case GDK_Up: 150 return VKEY_UP; // (26) UP ARROW key 151 case GDK_Right: 152 return VKEY_RIGHT; // (27) RIGHT ARROW key 153 case GDK_Down: 154 return VKEY_DOWN; // (28) DOWN ARROW key 155 case GDK_Select: 156 return VKEY_SELECT; // (29) SELECT key 157 case GDK_Print: 158 return VKEY_PRINT; // (2A) PRINT key 159 case GDK_Execute: 160 return VKEY_EXECUTE;// (2B) EXECUTE key 161 //dunno on this 162 //case GDK_PrintScreen: 163 // return VKEY_SNAPSHOT; // (2C) PRINT SCREEN key 164 case GDK_Insert: 165 return VKEY_INSERT; // (2D) INS key 166 case GDK_Delete: 167 return VKEY_DELETE; // (2E) DEL key 168 case GDK_Help: 169 return VKEY_HELP; // (2F) HELP key 170 case GDK_0: 171 case GDK_parenright: 172 return VKEY_0; // (30) 0) key 173 case GDK_1: 174 case GDK_exclam: 175 return VKEY_1; // (31) 1 ! key 176 case GDK_2: 177 case GDK_at: 178 return VKEY_2; // (32) 2 & key 179 case GDK_3: 180 case GDK_numbersign: 181 return VKEY_3; //case '3': case '#'; 182 case GDK_4: 183 case GDK_dollar: // (34) 4 key '$'; 184 return VKEY_4; 185 case GDK_5: 186 case GDK_percent: 187 return VKEY_5; // (35) 5 key '%' 188 case GDK_6: 189 case GDK_asciicircum: 190 return VKEY_6; // (36) 6 key '^' 191 case GDK_7: 192 case GDK_ampersand: 193 return VKEY_7; // (37) 7 key case '&' 194 case GDK_8: 195 case GDK_asterisk: 196 return VKEY_8; // (38) 8 key '*' 197 case GDK_9: 198 case GDK_parenleft: 199 return VKEY_9; // (39) 9 key '(' 200 case GDK_a: 201 case GDK_A: 202 return VKEY_A; // (41) A key case 'a': case 'A': return 0x41; 203 case GDK_b: 204 case GDK_B: 205 return VKEY_B; // (42) B key case 'b': case 'B': return 0x42; 206 case GDK_c: 207 case GDK_C: 208 return VKEY_C; // (43) C key case 'c': case 'C': return 0x43; 209 case GDK_d: 210 case GDK_D: 211 return VKEY_D; // (44) D key case 'd': case 'D': return 0x44; 212 case GDK_e: 213 case GDK_E: 214 return VKEY_E; // (45) E key case 'e': case 'E': return 0x45; 215 case GDK_f: 216 case GDK_F: 217 return VKEY_F; // (46) F key case 'f': case 'F': return 0x46; 218 case GDK_g: 219 case GDK_G: 220 return VKEY_G; // (47) G key case 'g': case 'G': return 0x47; 221 case GDK_h: 222 case GDK_H: 223 return VKEY_H; // (48) H key case 'h': case 'H': return 0x48; 224 case GDK_i: 225 case GDK_I: 226 return VKEY_I; // (49) I key case 'i': case 'I': return 0x49; 227 case GDK_j: 228 case GDK_J: 229 return VKEY_J; // (4A) J key case 'j': case 'J': return 0x4A; 230 case GDK_k: 231 case GDK_K: 232 return VKEY_K; // (4B) K key case 'k': case 'K': return 0x4B; 233 case GDK_l: 234 case GDK_L: 235 return VKEY_L; // (4C) L key case 'l': case 'L': return 0x4C; 236 case GDK_m: 237 case GDK_M: 238 return VKEY_M; // (4D) M key case 'm': case 'M': return 0x4D; 239 case GDK_n: 240 case GDK_N: 241 return VKEY_N; // (4E) N key case 'n': case 'N': return 0x4E; 242 case GDK_o: 243 case GDK_O: 244 return VKEY_O; // (4F) O key case 'o': case 'O': return 0x4F; 245 case GDK_p: 246 case GDK_P: 247 return VKEY_P; // (50) P key case 'p': case 'P': return 0x50; 248 case GDK_q: 249 case GDK_Q: 250 return VKEY_Q; // (51) Q key case 'q': case 'Q': return 0x51; 251 case GDK_r: 252 case GDK_R: 253 return VKEY_R; // (52) R key case 'r': case 'R': return 0x52; 254 case GDK_s: 255 case GDK_S: 256 return VKEY_S; // (53) S key case 's': case 'S': return 0x53; 257 case GDK_t: 258 case GDK_T: 259 return VKEY_T; // (54) T key case 't': case 'T': return 0x54; 260 case GDK_u: 261 case GDK_U: 262 return VKEY_U; // (55) U key case 'u': case 'U': return 0x55; 263 case GDK_v: 264 case GDK_V: 265 return VKEY_V; // (56) V key case 'v': case 'V': return 0x56; 266 case GDK_w: 267 case GDK_W: 268 return VKEY_W; // (57) W key case 'w': case 'W': return 0x57; 269 case GDK_x: 270 case GDK_X: 271 return VKEY_X; // (58) X key case 'x': case 'X': return 0x58; 272 case GDK_y: 273 case GDK_Y: 274 return VKEY_Y; // (59) Y key case 'y': case 'Y': return 0x59; 275 case GDK_z: 276 case GDK_Z: 277 return VKEY_Z; // (5A) Z key case 'z': case 'Z': return 0x5A; 278 case GDK_Meta_L: 279 case GDK_Super_L: 280 return VKEY_LWIN; // (5B) Left Windows key (Microsoft Natural keyboard) 281 case GDK_Meta_R: 282 case GDK_Super_R: 283 return VKEY_RWIN; // (5C) Right Windows key (Natural keyboard) 284 // VKEY_SLEEP (5F) Computer Sleep key 285 // VKEY_SEPARATOR (6C) Separator key 286 // VKEY_SUBTRACT (6D) Subtract key 287 // VKEY_DECIMAL (6E) Decimal key 288 // VKEY_DIVIDE (6F) Divide key 289 // handled by key code above 290 291 case GDK_Num_Lock: 292 return VKEY_NUMLOCK; // (90) NUM LOCK key 293 294 case GDK_Scroll_Lock: 295 return VKEY_SCROLL; // (91) SCROLL LOCK key 296 297 // VKEY_LSHIFT (A0) Left SHIFT key 298 // VKEY_RSHIFT (A1) Right SHIFT key 299 // VKEY_LCONTROL (A2) Left CONTROL key 300 // VKEY_RCONTROL (A3) Right CONTROL key 301 // VKEY_LMENU (A4) Left MENU key 302 // VKEY_RMENU (A5) Right MENU key 303 // VKEY_BROWSER_BACK (A6) Windows 2000/XP: Browser Back key 304 // VKEY_BROWSER_FORWARD (A7) Windows 2000/XP: Browser Forward key 305 // VKEY_BROWSER_REFRESH (A8) Windows 2000/XP: Browser Refresh key 306 // VKEY_BROWSER_STOP (A9) Windows 2000/XP: Browser Stop key 307 // VKEY_BROWSER_SEARCH (AA) Windows 2000/XP: Browser Search key 308 // VKEY_BROWSER_FAVORITES (AB) Windows 2000/XP: Browser Favorites key 309 // VKEY_BROWSER_HOME (AC) Windows 2000/XP: Browser Start and Home key 310 // VKEY_VOLUME_MUTE (AD) Windows 2000/XP: Volume Mute key 311 // VKEY_VOLUME_DOWN (AE) Windows 2000/XP: Volume Down key 312 // VKEY_VOLUME_UP (AF) Windows 2000/XP: Volume Up key 313 // VKEY_MEDIA_NEXT_TRACK (B0) Windows 2000/XP: Next Track key 314 // VKEY_MEDIA_PREV_TRACK (B1) Windows 2000/XP: Previous Track key 315 // VKEY_MEDIA_STOP (B2) Windows 2000/XP: Stop Media key 316 // VKEY_MEDIA_PLAY_PAUSE (B3) Windows 2000/XP: Play/Pause Media key 317 // VKEY_LAUNCH_MAIL (B4) Windows 2000/XP: Start Mail key 318 // VKEY_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key 319 // VKEY_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key 320 // VKEY_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key 321 322 // VKEY_OEM_1 (BA) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key 323 case GDK_semicolon: 324 case GDK_colon: 325 return VKEY_OEM_1; //case ';': case ':': return 0xBA; 326 // VKEY_OEM_PLUS (BB) Windows 2000/XP: For any country/region, the '+' key 327 case GDK_plus: 328 case GDK_equal: 329 return VKEY_OEM_PLUS; //case '=': case '+': return 0xBB; 330 // VKEY_OEM_COMMA (BC) Windows 2000/XP: For any country/region, the ',' key 331 case GDK_comma: 332 case GDK_less: 333 return VKEY_OEM_COMMA; //case ',': case '<': return 0xBC; 334 // VKEY_OEM_MINUS (BD) Windows 2000/XP: For any country/region, the '-' key 335 case GDK_minus: 336 case GDK_underscore: 337 return VKEY_OEM_MINUS; //case '-': case '_': return 0xBD; 338 // VKEY_OEM_PERIOD (BE) Windows 2000/XP: For any country/region, the '.' key 339 case GDK_period: 340 case GDK_greater: 341 return VKEY_OEM_PERIOD; //case '.': case '>': return 0xBE; 342 // VKEY_OEM_2 (BF) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key 343 case GDK_slash: 344 case GDK_question: 345 return VKEY_OEM_2; //case '/': case '?': return 0xBF; 346 // VKEY_OEM_3 (C0) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key 347 case GDK_asciitilde: 348 case GDK_quoteleft: 349 return VKEY_OEM_3; //case '`': case '~': return 0xC0; 350 // VKEY_OEM_4 (DB) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key 351 case GDK_bracketleft: 352 case GDK_braceleft: 353 return VKEY_OEM_4; //case '[': case '{': return 0xDB; 354 // VKEY_OEM_5 (DC) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key 355 case GDK_backslash: 356 case GDK_bar: 357 return VKEY_OEM_5; //case '\\': case '|': return 0xDC; 358 // VKEY_OEM_6 (DD) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key 359 case GDK_bracketright: 360 case GDK_braceright: 361 return VKEY_OEM_6; // case ']': case '}': return 0xDD; 362 // 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 363 case GDK_quoteright: 364 case GDK_quotedbl: 365 return VKEY_OEM_7; // case '\'': case '"': return 0xDE; 366 // VKEY_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard. 367 // VKEY_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard 368 // VKEY_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key 369 // 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 370 // VKEY_ATTN (F6) Attn key 371 // VKEY_CRSEL (F7) CrSel key 372 // VKEY_EXSEL (F8) ExSel key 373 // VKEY_EREOF (F9) Erase EOF key 374 // VKEY_PLAY (FA) Play key 375 // VKEY_ZOOM (FB) Zoom key 376 // VKEY_NONAME (FC) Reserved for future use 377 // VKEY_PA1 (FD) PA1 key 378 // VKEY_OEM_CLEAR (FE) Clear key 379 case GDK_F1: 380 case GDK_F2: 381 case GDK_F3: 382 case GDK_F4: 383 case GDK_F5: 384 case GDK_F6: 385 case GDK_F7: 386 case GDK_F8: 387 case GDK_F9: 388 case GDK_F10: 389 case GDK_F11: 390 case GDK_F12: 391 case GDK_F13: 392 case GDK_F14: 393 case GDK_F15: 394 case GDK_F16: 395 case GDK_F17: 396 case GDK_F18: 397 case GDK_F19: 398 case GDK_F20: 399 case GDK_F21: 400 case GDK_F22: 401 case GDK_F23: 402 case GDK_F24: 403 return VKEY_F1 + (keycode - GDK_F1); 404 default: 405 return 0; 406 } 407 } 408 409 } // namespace WebCore 410