comparison src/video/win32/SDL_win32events.c @ 2310:2f31ce8f1149

Undo keyboard layout based alphabetic key mapping. Grr.... HACK HACK HACK...
author Sam Lantinga <slouken@libsdl.org>
date Sat, 09 Feb 2008 07:18:38 +0000
parents 21591ae7355d
children 54e21acfec5a
comparison
equal deleted inserted replaced
2309:21591ae7355d 2310:2f31ce8f1149
44 #define WM_XBUTTONUP 0x020C 44 #define WM_XBUTTONUP 0x020C
45 #endif 45 #endif
46 #ifndef GET_XBUTTON_WPARAM 46 #ifndef GET_XBUTTON_WPARAM
47 #define GET_XBUTTON_WPARAM(w) (HIWORD(w)) 47 #define GET_XBUTTON_WPARAM(w) (HIWORD(w))
48 #endif 48 #endif
49
50 static WPARAM
51 RemapVKEY(WPARAM wParam, LPARAM lParam)
52 {
53 /* Windows remaps alphabetic keys based on current layout.
54 We try to provide USB scancodes, so undo this mapping.
55 */
56 if (wParam >= 'A' && wParam <= 'Z') {
57 /* Alphabetic scancodes for PC keyboards */
58 static BYTE scancodes[26] = {
59 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24,
60 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44
61 };
62 BYTE scancode = (lParam >> 16) & 0xFF;
63 int i;
64
65 if (scancode != scancodes[wParam - 'A']) {
66 for (i = 0; i < SDL_arraysize(scancodes); ++i) {
67 if (scancode == scancodes[i]) {
68 wParam = 'A' + i;
69 break;
70 }
71 }
72 }
73 }
74 return wParam;
75 }
49 76
50 LRESULT CALLBACK 77 LRESULT CALLBACK
51 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 78 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
52 { 79 {
53 SDL_WindowData *data; 80 SDL_WindowData *data;
308 if (lParam & REPEATED_KEYMASK) { 335 if (lParam & REPEATED_KEYMASK) {
309 return (0); 336 return (0);
310 } 337 }
311 338
312 index = data->videodata->keyboard; 339 index = data->videodata->keyboard;
340 wParam = RemapVKEY(wParam, lParam);
313 switch (wParam) { 341 switch (wParam) {
314 case VK_CONTROL: 342 case VK_CONTROL:
315 if (lParam & EXTENDED_KEYMASK) 343 if (lParam & EXTENDED_KEYMASK)
316 wParam = VK_RCONTROL; 344 wParam = VK_RCONTROL;
317 else 345 else
351 case WM_KEYUP: 379 case WM_KEYUP:
352 { 380 {
353 int index; 381 int index;
354 382
355 index = data->videodata->keyboard; 383 index = data->videodata->keyboard;
384 wParam = RemapVKEY(wParam, lParam);
356 switch (wParam) { 385 switch (wParam) {
357 case VK_CONTROL: 386 case VK_CONTROL:
358 if (lParam & EXTENDED_KEYMASK) 387 if (lParam & EXTENDED_KEYMASK)
359 wParam = VK_RCONTROL; 388 wParam = VK_RCONTROL;
360 else 389 else