comparison src/video/win32/SDL_win32events.c @ 2308:514f7c1651fc

Untested Win32 keyboard scancode code.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 08 Feb 2008 08:35:49 +0000
parents 545fbf461c5b
children 21591ae7355d
comparison
equal deleted inserted replaced
2307:47f8a579cd9b 2308:514f7c1651fc
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 SDLKey
51 TranslateKey(WPARAM vkey)
52 {
53 SDLKey key;
54
55 /* FIXME: Assign vkey directly to key if in ASCII range */
56 switch (vkey) {
57 case VK_BACK:
58 key = SDLK_BACKSPACE;
59 break;
60 case VK_TAB:
61 key = SDLK_TAB;
62 break;
63 case VK_CLEAR:
64 key = SDLK_CLEAR;
65 break;
66 case VK_RETURN:
67 key = SDLK_RETURN;
68 break;
69 case VK_PAUSE:
70 key = SDLK_PAUSE;
71 break;
72 case VK_ESCAPE:
73 key = SDLK_ESCAPE;
74 break;
75 case VK_SPACE:
76 key = SDLK_SPACE;
77 break;
78 case VK_APOSTROPHE:
79 key = SDLK_QUOTE;
80 break;
81 case VK_COMMA:
82 key = SDLK_COMMA;
83 break;
84 case VK_MINUS:
85 key = SDLK_MINUS;
86 break;
87 case VK_PERIOD:
88 key = SDLK_PERIOD;
89 break;
90 case VK_SLASH:
91 key = SDLK_SLASH;
92 break;
93 case VK_0:
94 key = SDLK_0;
95 break;
96 case VK_1:
97 key = SDLK_1;
98 break;
99 case VK_2:
100 key = SDLK_2;
101 break;
102 case VK_3:
103 key = SDLK_3;
104 break;
105 case VK_4:
106 key = SDLK_4;
107 break;
108 case VK_5:
109 key = SDLK_5;
110 break;
111 case VK_6:
112 key = SDLK_6;
113 break;
114 case VK_7:
115 key = SDLK_7;
116 break;
117 case VK_8:
118 key = SDLK_8;
119 break;
120 case VK_9:
121 key = SDLK_9;
122 break;
123 case VK_SEMICOLON:
124 key = SDLK_SEMICOLON;
125 break;
126 case VK_EQUALS:
127 key = SDLK_EQUALS;
128 break;
129 case VK_LBRACKET:
130 key = SDLK_LEFTBRACKET;
131 break;
132 case VK_BACKSLASH:
133 key = SDLK_BACKSLASH;
134 break;
135 case VK_OEM_102:
136 key = SDLK_LESS;
137 break;
138 case VK_RBRACKET:
139 key = SDLK_RIGHTBRACKET;
140 break;
141 case VK_GRAVE:
142 key = SDLK_BACKQUOTE;
143 break;
144 case VK_BACKTICK:
145 key = SDLK_BACKQUOTE;
146 break;
147 case VK_A:
148 key = SDLK_a;
149 break;
150 case VK_B:
151 key = SDLK_b;
152 break;
153 case VK_C:
154 key = SDLK_c;
155 break;
156 case VK_D:
157 key = SDLK_d;
158 break;
159 case VK_E:
160 key = SDLK_e;
161 break;
162 case VK_F:
163 key = SDLK_f;
164 break;
165 case VK_G:
166 key = SDLK_g;
167 break;
168 case VK_H:
169 key = SDLK_h;
170 break;
171 case VK_I:
172 key = SDLK_i;
173 break;
174 case VK_J:
175 key = SDLK_j;
176 break;
177 case VK_K:
178 key = SDLK_k;
179 break;
180 case VK_L:
181 key = SDLK_l;
182 break;
183 case VK_M:
184 key = SDLK_m;
185 break;
186 case VK_N:
187 key = SDLK_n;
188 break;
189 case VK_O:
190 key = SDLK_o;
191 break;
192 case VK_P:
193 key = SDLK_p;
194 break;
195 case VK_Q:
196 key = SDLK_q;
197 break;
198 case VK_R:
199 key = SDLK_r;
200 break;
201 case VK_S:
202 key = SDLK_s;
203 break;
204 case VK_T:
205 key = SDLK_t;
206 break;
207 case VK_U:
208 key = SDLK_u;
209 break;
210 case VK_V:
211 key = SDLK_v;
212 break;
213 case VK_W:
214 key = SDLK_w;
215 break;
216 case VK_X:
217 key = SDLK_x;
218 break;
219 case VK_Y:
220 key = SDLK_y;
221 break;
222 case VK_Z:
223 key = SDLK_z;
224 break;
225 case VK_DELETE:
226 key = SDLK_DELETE;
227 break;
228 case VK_NUMPAD0:
229 key = SDLK_KP0;
230 break;
231 case VK_NUMPAD1:
232 key = SDLK_KP1;
233 break;
234 case VK_NUMPAD2:
235 key = SDLK_KP2;
236 break;
237 case VK_NUMPAD3:
238 key = SDLK_KP3;
239 break;
240 case VK_NUMPAD4:
241 key = SDLK_KP4;
242 break;
243 case VK_NUMPAD5:
244 key = SDLK_KP5;
245 break;
246 case VK_NUMPAD6:
247 key = SDLK_KP6;
248 break;
249 case VK_NUMPAD7:
250 key = SDLK_KP7;
251 break;
252 case VK_NUMPAD8:
253 key = SDLK_KP8;
254 break;
255 case VK_NUMPAD9:
256 key = SDLK_KP9;
257 break;
258 case VK_DECIMAL:
259 key = SDLK_KP_PERIOD;
260 break;
261 case VK_DIVIDE:
262 key = SDLK_KP_DIVIDE;
263 break;
264 case VK_MULTIPLY:
265 key = SDLK_KP_MULTIPLY;
266 break;
267 case VK_SUBTRACT:
268 key = SDLK_KP_MINUS;
269 break;
270 case VK_ADD:
271 key = SDLK_KP_PLUS;
272 break;
273 case VK_UP:
274 key = SDLK_UP;
275 break;
276 case VK_DOWN:
277 key = SDLK_DOWN;
278 break;
279 case VK_RIGHT:
280 key = SDLK_RIGHT;
281 break;
282 case VK_LEFT:
283 key = SDLK_LEFT;
284 break;
285 case VK_INSERT:
286 key = SDLK_INSERT;
287 break;
288 case VK_HOME:
289 key = SDLK_HOME;
290 break;
291 case VK_END:
292 key = SDLK_END;
293 break;
294 case VK_PRIOR:
295 key = SDLK_PAGEUP;
296 break;
297 case VK_NEXT:
298 key = SDLK_PAGEDOWN;
299 break;
300 case VK_F1:
301 key = SDLK_F1;
302 break;
303 case VK_F2:
304 key = SDLK_F2;
305 break;
306 case VK_F3:
307 key = SDLK_F3;
308 break;
309 case VK_F4:
310 key = SDLK_F4;
311 break;
312 case VK_F5:
313 key = SDLK_F5;
314 break;
315 case VK_F6:
316 key = SDLK_F6;
317 break;
318 case VK_F7:
319 key = SDLK_F7;
320 break;
321 case VK_F8:
322 key = SDLK_F8;
323 break;
324 case VK_F9:
325 key = SDLK_F9;
326 break;
327 case VK_F10:
328 key = SDLK_F10;
329 break;
330 case VK_F11:
331 key = SDLK_F11;
332 break;
333 case VK_F12:
334 key = SDLK_F12;
335 break;
336 case VK_F13:
337 key = SDLK_F13;
338 break;
339 case VK_F14:
340 key = SDLK_F14;
341 break;
342 case VK_F15:
343 key = SDLK_F15;
344 break;
345 case VK_NUMLOCK:
346 key = SDLK_NUMLOCK;
347 break;
348 case VK_CAPITAL:
349 key = SDLK_CAPSLOCK;
350 break;
351 case VK_SCROLL:
352 key = SDLK_SCROLLOCK;
353 break;
354 case VK_RSHIFT:
355 key = SDLK_RSHIFT;
356 break;
357 case VK_LSHIFT:
358 key = SDLK_LSHIFT;
359 break;
360 case VK_RCONTROL:
361 key = SDLK_RCTRL;
362 break;
363 case VK_LCONTROL:
364 key = SDLK_LCTRL;
365 break;
366 case VK_RMENU:
367 key = SDLK_RALT;
368 break;
369 case VK_LMENU:
370 key = SDLK_LALT;
371 break;
372 case VK_RWIN:
373 key = SDLK_RSUPER;
374 break;
375 case VK_LWIN:
376 key = SDLK_LSUPER;
377 break;
378 case VK_HELP:
379 key = SDLK_HELP;
380 break;
381 case VK_PRINT:
382 key = SDLK_PRINT;
383 break;
384 case VK_SNAPSHOT:
385 key = SDLK_PRINT;
386 break;
387 case VK_CANCEL:
388 key = SDLK_BREAK;
389 break;
390 case VK_APPS:
391 key = SDLK_MENU;
392 break;
393 default:
394 key = SDLK_UNKNOWN;
395 break;
396 }
397 return key;
398 }
399 49
400 LRESULT CALLBACK 50 LRESULT CALLBACK
401 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 51 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
402 { 52 {
403 SDL_WindowData *data; 53 SDL_WindowData *data;
668 wParam = VK_LCONTROL; 318 wParam = VK_LCONTROL;
669 break; 319 break;
670 case VK_SHIFT: 320 case VK_SHIFT:
671 /* EXTENDED trick doesn't work here */ 321 /* EXTENDED trick doesn't work here */
672 { 322 {
673 Uint8 *state = SDL_GetKeyState(NULL); 323 Uint8 *state = SDL_GetKeyboardState(NULL);
674 if (state[SDLK_LSHIFT] == SDL_RELEASED 324 if (state[SDL_SCANCODE_LSHIFT] == SDL_RELEASED
675 && (GetKeyState(VK_LSHIFT) & 0x8000)) { 325 && (GetKeyState(VK_LSHIFT) & 0x8000)) {
676 wParam = VK_LSHIFT; 326 wParam = VK_LSHIFT;
677 } else if (state[SDLK_RSHIFT] == SDL_RELEASED 327 } else if (state[SDL_SCANCODE_RSHIFT] == SDL_RELEASED
678 && (GetKeyState(VK_RSHIFT) & 0x8000)) { 328 && (GetKeyState(VK_RSHIFT) & 0x8000)) {
679 wParam = VK_RSHIFT; 329 wParam = VK_RSHIFT;
680 } else { 330 } else {
681 /* Probably a key repeat */ 331 /* Probably a key repeat */
682 return (0); 332 return (0);
688 wParam = VK_RMENU; 338 wParam = VK_RMENU;
689 else 339 else
690 wParam = VK_LMENU; 340 wParam = VK_LMENU;
691 break; 341 break;
692 } 342 }
693 SDL_SendKeyboardKey(index, SDL_PRESSED, (Uint8) HIWORD(lParam), 343 if (wParam < 256) {
694 TranslateKey(wParam)); 344 SDL_SendKeyboardKey(index, SDL_PRESSED,
345 data->videodata->key_layout[wParam]);
346 }
695 } 347 }
696 return (0); 348 return (0);
697 349
698 case WM_SYSKEYUP: 350 case WM_SYSKEYUP:
699 case WM_KEYUP: 351 case WM_KEYUP:
709 wParam = VK_LCONTROL; 361 wParam = VK_LCONTROL;
710 break; 362 break;
711 case VK_SHIFT: 363 case VK_SHIFT:
712 /* EXTENDED trick doesn't work here */ 364 /* EXTENDED trick doesn't work here */
713 { 365 {
714 Uint8 *state = SDL_GetKeyState(NULL); 366 Uint8 *state = SDL_GetKeyboardState(NULL);
715 if (state[SDLK_LSHIFT] == SDL_PRESSED 367 if (state[SDL_SCANCODE_LSHIFT] == SDL_PRESSED
716 && !(GetKeyState(VK_LSHIFT) & 0x8000)) { 368 && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
717 wParam = VK_LSHIFT; 369 wParam = VK_LSHIFT;
718 } else if (state[SDLK_RSHIFT] == SDL_PRESSED 370 } else if (state[SDL_SCANCODE_RSHIFT] == SDL_PRESSED
719 && !(GetKeyState(VK_RSHIFT) & 0x8000)) { 371 && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
720 wParam = VK_RSHIFT; 372 wParam = VK_RSHIFT;
721 } else { 373 } else {
722 /* Probably a key repeat */ 374 /* Probably a key repeat */
723 return (0); 375 return (0);
731 wParam = VK_LMENU; 383 wParam = VK_LMENU;
732 break; 384 break;
733 } 385 }
734 /* Windows only reports keyup for print screen */ 386 /* Windows only reports keyup for print screen */
735 if (wParam == VK_SNAPSHOT 387 if (wParam == VK_SNAPSHOT
736 && SDL_GetKeyState(NULL)[SDLK_PRINT] == SDL_RELEASED) { 388 && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] ==
389 SDL_RELEASED) {
737 SDL_SendKeyboardKey(index, SDL_PRESSED, 390 SDL_SendKeyboardKey(index, SDL_PRESSED,
738 (Uint8) HIWORD(lParam), 391 data->videodata->key_layout[wParam]);
739 TranslateKey(wParam)); 392 }
740 } 393 if (wParam < 256) {
741 SDL_SendKeyboardKey(index, SDL_RELEASED, (Uint8) HIWORD(lParam), 394 SDL_SendKeyboardKey(index, SDL_RELEASED,
742 TranslateKey(wParam)); 395 data->videodata->key_layout[wParam]);
396 }
743 } 397 }
744 return (0); 398 return (0);
745 399
746 case WM_GETMINMAXINFO: 400 case WM_GETMINMAXINFO:
747 { 401 {