comparison src/video/windib/SDL_dibevents.c @ 1852:eb2d5480ae95

Try to keep SDL keysyms sane regardless of keyboard layout in windib target. Fixes Bugzilla #164.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 18 May 2006 03:24:10 +0000
parents 89f90f32f6c0
children c121d94672cb b2f59aadec0d
comparison
equal deleted inserted replaced
1851:536b0704b7d8 1852:eb2d5480ae95
120 if (state[SDLK_LSHIFT] == SDL_RELEASED && (GetKeyState(VK_LSHIFT) & 0x8000)) { 120 if (state[SDLK_LSHIFT] == SDL_RELEASED && (GetKeyState(VK_LSHIFT) & 0x8000)) {
121 wParam = VK_LSHIFT; 121 wParam = VK_LSHIFT;
122 } else if (state[SDLK_RSHIFT] == SDL_RELEASED && (GetKeyState(VK_RSHIFT) & 0x8000)) { 122 } else if (state[SDLK_RSHIFT] == SDL_RELEASED && (GetKeyState(VK_RSHIFT) & 0x8000)) {
123 wParam = VK_RSHIFT; 123 wParam = VK_RSHIFT;
124 } else { 124 } else {
125 /* Probably a key repeat */ 125 /* Win9x */
126 return(0); 126 int sc = HIWORD(lParam) & 0xFF;
127
128 if (sc == 0x2A)
129 wParam = VK_LSHIFT;
130 else
131 if (sc == 0x36)
132 wParam = VK_RSHIFT;
133 else
134 wParam = VK_LSHIFT;
127 } 135 }
128 } 136 }
129 break; 137 break;
130 case VK_MENU: 138 case VK_MENU:
131 if ( lParam&EXTENDED_KEYMASK ) 139 if ( lParam&EXTENDED_KEYMASK )
183 if (state[SDLK_LSHIFT] == SDL_PRESSED && !(GetKeyState(VK_LSHIFT) & 0x8000)) { 191 if (state[SDLK_LSHIFT] == SDL_PRESSED && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
184 wParam = VK_LSHIFT; 192 wParam = VK_LSHIFT;
185 } else if (state[SDLK_RSHIFT] == SDL_PRESSED && !(GetKeyState(VK_RSHIFT) & 0x8000)) { 193 } else if (state[SDLK_RSHIFT] == SDL_PRESSED && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
186 wParam = VK_RSHIFT; 194 wParam = VK_RSHIFT;
187 } else { 195 } else {
188 /* Probably a key repeat */ 196 /* Win9x */
189 return(0); 197 int sc = HIWORD(lParam) & 0xFF;
198
199 if (sc == 0x2A)
200 wParam = VK_LSHIFT;
201 else
202 if (sc == 0x36)
203 wParam = VK_RSHIFT;
204 else
205 wParam = VK_LSHIFT;
190 } 206 }
191 } 207 }
192 break; 208 break;
193 case VK_MENU: 209 case VK_MENU:
194 if ( lParam&EXTENDED_KEYMASK ) 210 if ( lParam&EXTENDED_KEYMASK )
250 DispatchMessage(&msg); 266 DispatchMessage(&msg);
251 } 267 }
252 } 268 }
253 } 269 }
254 270
271 static HKL hLayoutUS = NULL;
272
255 void DIB_InitOSKeymap(_THIS) 273 void DIB_InitOSKeymap(_THIS)
256 { 274 {
257 int i; 275 int i;
276 char current_layout[256];
277
278 GetKeyboardLayoutName(current_layout);
279 //printf("Initial Keyboard Layout Name: '%s'\n", current_layout);
280
281 hLayoutUS = LoadKeyboardLayout("00000409", KLF_NOTELLSHELL);
282 if (!hLayoutUS) {
283 //printf("Failed to load US keyboard layout. Using current.\n");
284 hLayoutUS = GetKeyboardLayout(0);
285 }
286 LoadKeyboardLayout(current_layout, KLF_ACTIVATE);
258 287
259 /* Map the VK keysyms */ 288 /* Map the VK keysyms */
260 for ( i=0; i<SDL_arraysize(VK_keymap); ++i ) 289 for ( i=0; i<SDL_arraysize(VK_keymap); ++i )
261 VK_keymap[i] = SDLK_UNKNOWN; 290 VK_keymap[i] = SDLK_UNKNOWN;
262 291
379 VK_keymap[VK_SNAPSHOT] = SDLK_PRINT; 408 VK_keymap[VK_SNAPSHOT] = SDLK_PRINT;
380 VK_keymap[VK_CANCEL] = SDLK_BREAK; 409 VK_keymap[VK_CANCEL] = SDLK_BREAK;
381 VK_keymap[VK_APPS] = SDLK_MENU; 410 VK_keymap[VK_APPS] = SDLK_MENU;
382 } 411 }
383 412
413 #define EXTKEYPAD(keypad) ((scancode & 0x100)?(mvke):(keypad))
414
415 static int SDL_MapVirtualKey(int scancode, int vkey)
416 {
417 int mvke = MapVirtualKeyEx(scancode & 0xFF, 1, hLayoutUS);
418
419 switch(vkey) {
420 /* These are always correct */
421 case VK_DIVIDE:
422 case VK_MULTIPLY:
423 case VK_SUBTRACT:
424 case VK_ADD:
425 case VK_LWIN:
426 case VK_RWIN:
427 case VK_APPS:
428 /* These are already handled */
429 case VK_LCONTROL:
430 case VK_RCONTROL:
431 case VK_LSHIFT:
432 case VK_RSHIFT:
433 case VK_LMENU:
434 case VK_RMENU:
435 case VK_SNAPSHOT:
436 case VK_PAUSE:
437 return vkey;
438 }
439 switch(mvke) {
440 /* Distinguish between keypad and extended keys */
441 case VK_INSERT: return EXTKEYPAD(VK_NUMPAD0);
442 case VK_DELETE: return EXTKEYPAD(VK_DECIMAL);
443 case VK_END: return EXTKEYPAD(VK_NUMPAD1);
444 case VK_DOWN: return EXTKEYPAD(VK_NUMPAD2);
445 case VK_NEXT: return EXTKEYPAD(VK_NUMPAD3);
446 case VK_LEFT: return EXTKEYPAD(VK_NUMPAD4);
447 case VK_CLEAR: return EXTKEYPAD(VK_NUMPAD5);
448 case VK_RIGHT: return EXTKEYPAD(VK_NUMPAD6);
449 case VK_HOME: return EXTKEYPAD(VK_NUMPAD7);
450 case VK_UP: return EXTKEYPAD(VK_NUMPAD8);
451 case VK_PRIOR: return EXTKEYPAD(VK_NUMPAD9);
452 }
453 return mvke?mvke:vkey;
454 }
455
384 static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed) 456 static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed)
385 { 457 {
386 /* Set the keysym information */ 458 /* Set the keysym information */
387 keysym->scancode = (unsigned char) scancode; 459 keysym->scancode = (unsigned char) scancode;
388 keysym->sym = VK_keymap[vkey];
389 keysym->mod = KMOD_NONE; 460 keysym->mod = KMOD_NONE;
390 keysym->unicode = 0; 461 keysym->unicode = 0;
391 if ( pressed && SDL_TranslateUNICODE ) { 462 if ( pressed && SDL_TranslateUNICODE ) {
392 #ifdef NO_GETKEYBOARDSTATE 463 #ifdef NO_GETKEYBOARDSTATE
393 /* Uh oh, better hope the vkey is close enough.. */ 464 /* Uh oh, better hope the vkey is close enough.. */
401 { 472 {
402 keysym->unicode = wchars[0]; 473 keysym->unicode = wchars[0];
403 } 474 }
404 #endif /* NO_GETKEYBOARDSTATE */ 475 #endif /* NO_GETKEYBOARDSTATE */
405 } 476 }
477
478 if ((vkey == VK_RETURN) && (scancode & 0x100)) {
479 /* No VK_ code for the keypad enter key */
480 keysym->sym = SDLK_KP_ENTER;
481 }
482 else {
483 keysym->sym = VK_keymap[SDL_MapVirtualKey(scancode, vkey)];
484 }
485
486 #if 0
487 {
488 HKL hLayoutCurrent = GetKeyboardLayout(0);
489 int sc = scancode & 0xFF;
490
491 printf("SYM:%d, VK:0x%02X, SC:0x%04X, US:(1:0x%02X, 3:0x%02X), "
492 "Current:(1:0x%02X, 3:0x%02X)\n",
493 keysym->sym, vkey, scancode,
494 MapVirtualKeyEx(sc, 1, hLayoutUS),
495 MapVirtualKeyEx(sc, 3, hLayoutUS),
496 MapVirtualKeyEx(sc, 1, hLayoutCurrent),
497 MapVirtualKeyEx(sc, 3, hLayoutCurrent)
498 );
499 }
500 #endif
406 return(keysym); 501 return(keysym);
407 } 502 }
408 503
409 int DIB_CreateWindow(_THIS) 504 int DIB_CreateWindow(_THIS)
410 { 505 {