24 #include "SDL_win32video.h" |
24 #include "SDL_win32video.h" |
25 |
25 |
26 #include "../../events/SDL_keyboard_c.h" |
26 #include "../../events/SDL_keyboard_c.h" |
27 #include "../../events/scancodes_win32.h" |
27 #include "../../events/scancodes_win32.h" |
28 |
28 |
|
29 #ifndef MAPVK_VK_TO_VSC |
|
30 #define MAPVK_VK_TO_VSC 0 |
|
31 #endif |
|
32 #ifndef MAPVK_VSC_TO_VK |
|
33 #define MAPVK_VSC_TO_VK 1 |
|
34 #endif |
|
35 #ifndef MAPVK_VK_TO_CHAR |
|
36 #define MAPVK_VK_TO_CHAR 2 |
|
37 #endif |
|
38 |
|
39 /* Alphabetic scancodes for PC keyboards */ |
|
40 BYTE alpha_scancodes[26] = { |
|
41 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, |
|
42 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44 |
|
43 }; |
|
44 |
29 void |
45 void |
30 WIN_InitKeyboard(_THIS) |
46 WIN_InitKeyboard(_THIS) |
31 { |
47 { |
32 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
48 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
33 SDL_Keyboard keyboard; |
49 SDL_Keyboard keyboard; |
|
50 int i; |
|
51 |
|
52 /* Make sure the alpha scancodes are correct. T isn't usually remapped */ |
|
53 if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T'-'A']) { |
|
54 printf("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n"); |
|
55 for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) { |
|
56 alpha_scancodes[i] = MapVirtualKey('A'+i, MAPVK_VK_TO_VSC); |
|
57 printf("%d = %d\n", i, alpha_scancodes[i]); |
|
58 } |
|
59 } |
34 |
60 |
35 data->key_layout = win32_scancode_table; |
61 data->key_layout = win32_scancode_table; |
36 |
62 |
37 SDL_zero(keyboard); |
63 SDL_zero(keyboard); |
38 data->keyboard = SDL_AddKeyboard(&keyboard, -1); |
64 data->keyboard = SDL_AddKeyboard(&keyboard, -1); |
39 WIN_UpdateKeymap(_this); |
65 WIN_UpdateKeymap(data->keyboard); |
40 |
66 |
41 SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu"); |
67 SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu"); |
42 SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows"); |
68 SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows"); |
43 SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Windows"); |
69 SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Windows"); |
44 } |
70 } |
45 |
71 |
46 void |
72 void |
47 WIN_UpdateKeymap(_THIS) |
73 WIN_UpdateKeymap(int keyboard) |
48 { |
74 { |
49 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
|
50 int i; |
75 int i; |
51 SDL_scancode scancode; |
76 SDL_scancode scancode; |
52 SDLKey keymap[SDL_NUM_SCANCODES]; |
77 SDLKey keymap[SDL_NUM_SCANCODES]; |
53 |
78 |
54 SDL_GetDefaultKeymap(keymap); |
79 SDL_GetDefaultKeymap(keymap); |
59 scancode = win32_scancode_table[i]; |
84 scancode = win32_scancode_table[i]; |
60 if (scancode == SDL_SCANCODE_UNKNOWN || |
85 if (scancode == SDL_SCANCODE_UNKNOWN || |
61 (keymap[scancode] & SDLK_SCANCODE_MASK)) { |
86 (keymap[scancode] & SDLK_SCANCODE_MASK)) { |
62 continue; |
87 continue; |
63 } |
88 } |
64 #ifndef MAPVK_VK_TO_CHAR |
89 |
65 #define MAPVK_VK_TO_CHAR 2 |
90 /* Alphabetic keys are handled specially, since Windows remaps them */ |
66 #endif |
91 if (i >= 'A' && i <= 'Z') { |
67 keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF); |
92 BYTE vsc = alpha_scancodes[i-'A']; |
|
93 keymap[scancode] = MapVirtualKey(vsc, MAPVK_VSC_TO_VK) + 0x20; |
|
94 } else { |
|
95 keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF); |
|
96 } |
68 } |
97 } |
69 SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES); |
98 SDL_SetKeymap(keyboard, 0, keymap, SDL_NUM_SCANCODES); |
70 } |
99 } |
71 |
100 |
72 void |
101 void |
73 WIN_QuitKeyboard(_THIS) |
102 WIN_QuitKeyboard(_THIS) |
74 { |
103 { |