comparison src/video/windib/SDL_dibevents.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents eb2d5480ae95
children
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
41 #define NO_GETKEYBOARDSTATE 41 #define NO_GETKEYBOARDSTATE
42 #endif 42 #endif
43 43
44 /* The translation table from a Microsoft VK keysym to a SDL keysym */ 44 /* The translation table from a Microsoft VK keysym to a SDL keysym */
45 static SDLKey VK_keymap[SDLK_LAST]; 45 static SDLKey VK_keymap[SDLK_LAST];
46 static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed); 46 static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode,
47 SDL_keysym * keysym, int pressed);
47 48
48 /* Masks for processing the windows KEYDOWN and KEYUP messages */ 49 /* Masks for processing the windows KEYDOWN and KEYUP messages */
49 #define REPEATED_KEYMASK (1<<30) 50 #define REPEATED_KEYMASK (1<<30)
50 #define EXTENDED_KEYMASK (1<<24) 51 #define EXTENDED_KEYMASK (1<<24)
51 52
59 static WNDPROCTYPE userWindowProc = NULL; 60 static WNDPROCTYPE userWindowProc = NULL;
60 61
61 62
62 #ifdef _WIN32_WCE 63 #ifdef _WIN32_WCE
63 64
64 WPARAM rotateKey(WPARAM key,SDL_ScreenOrientation direction) 65 WPARAM
65 { 66 rotateKey(WPARAM key, SDL_ScreenOrientation direction)
66 if (direction != SDL_ORIENTATION_LEFT) 67 {
67 return key; 68 if (direction != SDL_ORIENTATION_LEFT)
68 69 return key;
69 switch (key) { 70
70 case 0x26: /* up */ 71 switch (key) {
71 return 0x27; 72 case 0x26: /* up */
72 case 0x27: /* right */ 73 return 0x27;
73 return 0x28; 74 case 0x27: /* right */
74 case 0x28: /* down */ 75 return 0x28;
75 return 0x25; 76 case 0x28: /* down */
76 case 0x25: /* left */ 77 return 0x25;
77 return 0x26; 78 case 0x25: /* left */
78 } 79 return 0x26;
79 80 }
80 return key; 81
81 } 82 return key;
82 83 }
83 #endif 84
85 #endif
84 86
85 87
86 /* The main Win32 event handler */ 88 /* The main Win32 event handler */
87 LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 89 LRESULT
88 { 90 DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
89 extern int posted; 91 {
90 92 extern int posted;
91 switch (msg) { 93
92 case WM_SYSKEYDOWN: 94 switch (msg) {
93 case WM_KEYDOWN: { 95 case WM_SYSKEYDOWN:
94 SDL_keysym keysym; 96 case WM_KEYDOWN:
97 {
98 SDL_keysym keysym;
95 99
96 #ifdef _WIN32_WCE 100 #ifdef _WIN32_WCE
97 // Drop GAPI artefacts 101 // Drop GAPI artefacts
98 if (wParam == 0x84 || wParam == 0x5B) 102 if (wParam == 0x84 || wParam == 0x5B)
99 return 0; 103 return 0;
100 104
101 // Rotate key if necessary 105 // Rotate key if necessary
102 if (this->hidden->orientation != SDL_ORIENTATION_UP) 106 if (this->hidden->orientation != SDL_ORIENTATION_UP)
103 wParam = rotateKey(wParam, this->hidden->orientation); 107 wParam = rotateKey(wParam, this->hidden->orientation);
104 #endif 108 #endif
105 /* Ignore repeated keys */ 109 /* Ignore repeated keys */
106 if ( lParam&REPEATED_KEYMASK ) { 110 if (lParam & REPEATED_KEYMASK) {
107 return(0); 111 return (0);
108 } 112 }
109 switch (wParam) { 113 switch (wParam) {
110 case VK_CONTROL: 114 case VK_CONTROL:
111 if ( lParam&EXTENDED_KEYMASK ) 115 if (lParam & EXTENDED_KEYMASK)
112 wParam = VK_RCONTROL; 116 wParam = VK_RCONTROL;
113 else 117 else
114 wParam = VK_LCONTROL; 118 wParam = VK_LCONTROL;
115 break; 119 break;
116 case VK_SHIFT: 120 case VK_SHIFT:
117 /* EXTENDED trick doesn't work here */ 121 /* EXTENDED trick doesn't work here */
118 { 122 {
119 Uint8 *state = SDL_GetKeyState(NULL); 123 Uint8 *state = SDL_GetKeyState(NULL);
120 if (state[SDLK_LSHIFT] == SDL_RELEASED && (GetKeyState(VK_LSHIFT) & 0x8000)) { 124 if (state[SDLK_LSHIFT] == SDL_RELEASED
121 wParam = VK_LSHIFT; 125 && (GetKeyState(VK_LSHIFT) & 0x8000)) {
122 } else if (state[SDLK_RSHIFT] == SDL_RELEASED && (GetKeyState(VK_RSHIFT) & 0x8000)) { 126 wParam = VK_LSHIFT;
123 wParam = VK_RSHIFT; 127 } else if (state[SDLK_RSHIFT] == SDL_RELEASED
124 } else { 128 && (GetKeyState(VK_RSHIFT) & 0x8000)) {
125 /* Win9x */ 129 wParam = VK_RSHIFT;
126 int sc = HIWORD(lParam) & 0xFF; 130 } else {
127 131 /* Probably a key repeat */
128 if (sc == 0x2A) 132 return (0);
129 wParam = VK_LSHIFT; 133 }
130 else 134 }
131 if (sc == 0x36) 135 break;
132 wParam = VK_RSHIFT; 136 case VK_MENU:
133 else 137 if (lParam & EXTENDED_KEYMASK)
134 wParam = VK_LSHIFT; 138 wParam = VK_RMENU;
135 } 139 else
136 } 140 wParam = VK_LMENU;
137 break; 141 break;
138 case VK_MENU: 142 }
139 if ( lParam&EXTENDED_KEYMASK )
140 wParam = VK_RMENU;
141 else
142 wParam = VK_LMENU;
143 break;
144 }
145 #ifdef NO_GETKEYBOARDSTATE 143 #ifdef NO_GETKEYBOARDSTATE
146 /* this is the workaround for the missing ToAscii() and ToUnicode() in CE (not necessary at KEYUP!) */ 144 /* this is the workaround for the missing ToAscii() and ToUnicode() in CE (not necessary at KEYUP!) */
147 if ( SDL_TranslateUNICODE ) { 145 if (SDL_TranslateUNICODE) {
148 MSG m; 146 MSG m;
149 147
150 m.hwnd = hwnd; 148 m.hwnd = hwnd;
151 m.message = msg; 149 m.message = msg;
152 m.wParam = wParam; 150 m.wParam = wParam;
153 m.lParam = lParam; 151 m.lParam = lParam;
154 m.time = 0; 152 m.time = 0;
155 if ( TranslateMessage(&m) && PeekMessage(&m, hwnd, 0, WM_USER, PM_NOREMOVE) && (m.message == WM_CHAR) ) { 153 if (TranslateMessage(&m)
156 GetMessage(&m, hwnd, 0, WM_USER); 154 && PeekMessage(&m, hwnd, 0, WM_USER, PM_NOREMOVE)
157 wParam = m.wParam; 155 && (m.message == WM_CHAR)) {
158 } 156 GetMessage(&m, hwnd, 0, WM_USER);
159 } 157 wParam = m.wParam;
158 }
159 }
160 #endif /* NO_GETKEYBOARDSTATE */ 160 #endif /* NO_GETKEYBOARDSTATE */
161 posted = SDL_PrivateKeyboard(SDL_PRESSED, 161 posted = SDL_PrivateKeyboard(SDL_PRESSED,
162 TranslateKey(wParam,HIWORD(lParam),&keysym,1)); 162 TranslateKey(wParam,
163 } 163 HIWORD(lParam),
164 return(0); 164 &keysym, 1));
165 165 }
166 case WM_SYSKEYUP: 166 return (0);
167 case WM_KEYUP: { 167
168 SDL_keysym keysym; 168 case WM_SYSKEYUP:
169 case WM_KEYUP:
170 {
171 SDL_keysym keysym;
169 172
170 #ifdef _WIN32_WCE 173 #ifdef _WIN32_WCE
171 // Drop GAPI artifacts 174 // Drop GAPI artifacts
172 if (wParam == 0x84 || wParam == 0x5B) 175 if (wParam == 0x84 || wParam == 0x5B)
173 return 0; 176 return 0;
174 177
175 // Rotate key if necessary 178 // Rotate key if necessary
176 if (this->hidden->orientation != SDL_ORIENTATION_UP) 179 if (this->hidden->orientation != SDL_ORIENTATION_UP)
177 wParam = rotateKey(wParam, this->hidden->orientation); 180 wParam = rotateKey(wParam, this->hidden->orientation);
178 #endif 181 #endif
179 182
180 switch (wParam) { 183 switch (wParam) {
181 case VK_CONTROL: 184 case VK_CONTROL:
182 if ( lParam&EXTENDED_KEYMASK ) 185 if (lParam & EXTENDED_KEYMASK)
183 wParam = VK_RCONTROL; 186 wParam = VK_RCONTROL;
184 else 187 else
185 wParam = VK_LCONTROL; 188 wParam = VK_LCONTROL;
186 break; 189 break;
187 case VK_SHIFT: 190 case VK_SHIFT:
188 /* EXTENDED trick doesn't work here */ 191 /* EXTENDED trick doesn't work here */
189 { 192 {
190 Uint8 *state = SDL_GetKeyState(NULL); 193 Uint8 *state = SDL_GetKeyState(NULL);
191 if (state[SDLK_LSHIFT] == SDL_PRESSED && !(GetKeyState(VK_LSHIFT) & 0x8000)) { 194 if (state[SDLK_LSHIFT] == SDL_PRESSED
192 wParam = VK_LSHIFT; 195 && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
193 } else if (state[SDLK_RSHIFT] == SDL_PRESSED && !(GetKeyState(VK_RSHIFT) & 0x8000)) { 196 wParam = VK_LSHIFT;
194 wParam = VK_RSHIFT; 197 } else if (state[SDLK_RSHIFT] == SDL_PRESSED
195 } else { 198 && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
196 /* Win9x */ 199 wParam = VK_RSHIFT;
197 int sc = HIWORD(lParam) & 0xFF; 200 } else {
198 201 /* Probably a key repeat */
199 if (sc == 0x2A) 202 return (0);
200 wParam = VK_LSHIFT; 203 }
201 else 204 }
202 if (sc == 0x36) 205 break;
203 wParam = VK_RSHIFT; 206 case VK_MENU:
204 else 207 if (lParam & EXTENDED_KEYMASK)
205 wParam = VK_LSHIFT; 208 wParam = VK_RMENU;
206 } 209 else
207 } 210 wParam = VK_LMENU;
208 break; 211 break;
209 case VK_MENU: 212 }
210 if ( lParam&EXTENDED_KEYMASK ) 213 /* Windows only reports keyup for print screen */
211 wParam = VK_RMENU; 214 if (wParam == VK_SNAPSHOT
212 else 215 && SDL_GetKeyState(NULL)[SDLK_PRINT] == SDL_RELEASED) {
213 wParam = VK_LMENU; 216 posted = SDL_PrivateKeyboard(SDL_PRESSED,
214 break; 217 TranslateKey(wParam,
215 } 218 HIWORD
216 /* Windows only reports keyup for print screen */ 219 (lParam),
217 if ( wParam == VK_SNAPSHOT && SDL_GetKeyState(NULL)[SDLK_PRINT] == SDL_RELEASED ) { 220 &keysym, 1));
218 posted = SDL_PrivateKeyboard(SDL_PRESSED, 221 }
219 TranslateKey(wParam,HIWORD(lParam),&keysym,1)); 222 posted = SDL_PrivateKeyboard(SDL_RELEASED,
220 } 223 TranslateKey(wParam,
221 posted = SDL_PrivateKeyboard(SDL_RELEASED, 224 HIWORD(lParam),
222 TranslateKey(wParam,HIWORD(lParam),&keysym,0)); 225 &keysym, 0));
223 } 226 }
224 return(0); 227 return (0);
225 228
226 #if defined(SC_SCREENSAVE) && defined(SC_MONITORPOWER) 229 #if defined(SC_SCREENSAVE) && defined(SC_MONITORPOWER)
227 case WM_SYSCOMMAND: { 230 case WM_SYSCOMMAND:
228 if ((wParam&0xFFF0)==SC_SCREENSAVE || 231 {
229 (wParam&0xFFF0)==SC_MONITORPOWER) 232 if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
230 return(0); 233 (wParam & 0xFFF0) == SC_MONITORPOWER)
231 } 234 return (0);
232 /* Fall through to default processing */ 235 }
236 /* Fall through to default processing */
233 #endif /* SC_SCREENSAVE && SC_MONITORPOWER */ 237 #endif /* SC_SCREENSAVE && SC_MONITORPOWER */
234 238
235 default: { 239 default:
236 /* Only post the event if we're watching for it */ 240 {
237 if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { 241 /* Only post the event if we're watching for it */
238 SDL_SysWMmsg wmmsg; 242 if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
239 243 SDL_SysWMmsg wmmsg;
240 SDL_VERSION(&wmmsg.version); 244
241 wmmsg.hwnd = hwnd; 245 SDL_VERSION(&wmmsg.version);
242 wmmsg.msg = msg; 246 wmmsg.hwnd = hwnd;
243 wmmsg.wParam = wParam; 247 wmmsg.msg = msg;
244 wmmsg.lParam = lParam; 248 wmmsg.wParam = wParam;
245 posted = SDL_PrivateSysWMEvent(&wmmsg); 249 wmmsg.lParam = lParam;
246 250 posted = SDL_PrivateSysWMEvent(&wmmsg);
247 /* DJM: If the user isn't watching for private 251
248 messages in her SDL event loop, then pass it 252 /* DJM: If the user isn't watching for private
249 along to any win32 specific window proc. 253 messages in her SDL event loop, then pass it
250 */ 254 along to any win32 specific window proc.
251 } else if (userWindowProc) { 255 */
252 return CallWindowProc(userWindowProc, hwnd, msg, wParam, lParam); 256 } else if (userWindowProc) {
253 } 257 return CallWindowProc(userWindowProc, hwnd, msg, wParam,
254 } 258 lParam);
255 break; 259 }
256 } 260 }
257 return(DefWindowProc(hwnd, msg, wParam, lParam)); 261 break;
258 } 262 }
259 263 return (DefWindowProc(hwnd, msg, wParam, lParam));
260 void DIB_PumpEvents(_THIS) 264 }
261 { 265
262 MSG msg; 266 void
263 267 DIB_PumpEvents(_THIS)
264 while ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { 268 {
265 if ( GetMessage(&msg, NULL, 0, 0) > 0 ) { 269 MSG msg;
266 DispatchMessage(&msg); 270
267 } 271 while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
268 } 272 if (GetMessage(&msg, NULL, 0, 0) > 0) {
269 } 273 DispatchMessage(&msg);
270 274 }
271 static HKL hLayoutUS = NULL; 275 }
272 276 }
273 void DIB_InitOSKeymap(_THIS) 277
274 { 278 void
275 int i; 279 DIB_InitOSKeymap(_THIS)
276 char current_layout[256]; 280 {
277 281 int i;
278 GetKeyboardLayoutName(current_layout); 282
279 //printf("Initial Keyboard Layout Name: '%s'\n", current_layout); 283 /* Map the VK keysyms */
280 284 for (i = 0; i < SDL_arraysize(VK_keymap); ++i)
281 hLayoutUS = LoadKeyboardLayout("00000409", KLF_NOTELLSHELL); 285 VK_keymap[i] = SDLK_UNKNOWN;
282 if (!hLayoutUS) { 286
283 //printf("Failed to load US keyboard layout. Using current.\n"); 287 VK_keymap[VK_BACK] = SDLK_BACKSPACE;
284 hLayoutUS = GetKeyboardLayout(0); 288 VK_keymap[VK_TAB] = SDLK_TAB;
285 } 289 VK_keymap[VK_CLEAR] = SDLK_CLEAR;
286 LoadKeyboardLayout(current_layout, KLF_ACTIVATE); 290 VK_keymap[VK_RETURN] = SDLK_RETURN;
287 291 VK_keymap[VK_PAUSE] = SDLK_PAUSE;
288 /* Map the VK keysyms */ 292 VK_keymap[VK_ESCAPE] = SDLK_ESCAPE;
289 for ( i=0; i<SDL_arraysize(VK_keymap); ++i ) 293 VK_keymap[VK_SPACE] = SDLK_SPACE;
290 VK_keymap[i] = SDLK_UNKNOWN; 294 VK_keymap[VK_APOSTROPHE] = SDLK_QUOTE;
291 295 VK_keymap[VK_COMMA] = SDLK_COMMA;
292 VK_keymap[VK_BACK] = SDLK_BACKSPACE; 296 VK_keymap[VK_MINUS] = SDLK_MINUS;
293 VK_keymap[VK_TAB] = SDLK_TAB; 297 VK_keymap[VK_PERIOD] = SDLK_PERIOD;
294 VK_keymap[VK_CLEAR] = SDLK_CLEAR; 298 VK_keymap[VK_SLASH] = SDLK_SLASH;
295 VK_keymap[VK_RETURN] = SDLK_RETURN; 299 VK_keymap[VK_0] = SDLK_0;
296 VK_keymap[VK_PAUSE] = SDLK_PAUSE; 300 VK_keymap[VK_1] = SDLK_1;
297 VK_keymap[VK_ESCAPE] = SDLK_ESCAPE; 301 VK_keymap[VK_2] = SDLK_2;
298 VK_keymap[VK_SPACE] = SDLK_SPACE; 302 VK_keymap[VK_3] = SDLK_3;
299 VK_keymap[VK_APOSTROPHE] = SDLK_QUOTE; 303 VK_keymap[VK_4] = SDLK_4;
300 VK_keymap[VK_COMMA] = SDLK_COMMA; 304 VK_keymap[VK_5] = SDLK_5;
301 VK_keymap[VK_MINUS] = SDLK_MINUS; 305 VK_keymap[VK_6] = SDLK_6;
302 VK_keymap[VK_PERIOD] = SDLK_PERIOD; 306 VK_keymap[VK_7] = SDLK_7;
303 VK_keymap[VK_SLASH] = SDLK_SLASH; 307 VK_keymap[VK_8] = SDLK_8;
304 VK_keymap[VK_0] = SDLK_0; 308 VK_keymap[VK_9] = SDLK_9;
305 VK_keymap[VK_1] = SDLK_1; 309 VK_keymap[VK_SEMICOLON] = SDLK_SEMICOLON;
306 VK_keymap[VK_2] = SDLK_2; 310 VK_keymap[VK_EQUALS] = SDLK_EQUALS;
307 VK_keymap[VK_3] = SDLK_3; 311 VK_keymap[VK_LBRACKET] = SDLK_LEFTBRACKET;
308 VK_keymap[VK_4] = SDLK_4; 312 VK_keymap[VK_BACKSLASH] = SDLK_BACKSLASH;
309 VK_keymap[VK_5] = SDLK_5; 313 VK_keymap[VK_OEM_102] = SDLK_LESS;
310 VK_keymap[VK_6] = SDLK_6; 314 VK_keymap[VK_RBRACKET] = SDLK_RIGHTBRACKET;
311 VK_keymap[VK_7] = SDLK_7; 315 VK_keymap[VK_GRAVE] = SDLK_BACKQUOTE;
312 VK_keymap[VK_8] = SDLK_8; 316 VK_keymap[VK_BACKTICK] = SDLK_BACKQUOTE;
313 VK_keymap[VK_9] = SDLK_9; 317 VK_keymap[VK_A] = SDLK_a;
314 VK_keymap[VK_SEMICOLON] = SDLK_SEMICOLON; 318 VK_keymap[VK_B] = SDLK_b;
315 VK_keymap[VK_EQUALS] = SDLK_EQUALS; 319 VK_keymap[VK_C] = SDLK_c;
316 VK_keymap[VK_LBRACKET] = SDLK_LEFTBRACKET; 320 VK_keymap[VK_D] = SDLK_d;
317 VK_keymap[VK_BACKSLASH] = SDLK_BACKSLASH; 321 VK_keymap[VK_E] = SDLK_e;
318 VK_keymap[VK_OEM_102] = SDLK_LESS; 322 VK_keymap[VK_F] = SDLK_f;
319 VK_keymap[VK_RBRACKET] = SDLK_RIGHTBRACKET; 323 VK_keymap[VK_G] = SDLK_g;
320 VK_keymap[VK_GRAVE] = SDLK_BACKQUOTE; 324 VK_keymap[VK_H] = SDLK_h;
321 VK_keymap[VK_BACKTICK] = SDLK_BACKQUOTE; 325 VK_keymap[VK_I] = SDLK_i;
322 VK_keymap[VK_A] = SDLK_a; 326 VK_keymap[VK_J] = SDLK_j;
323 VK_keymap[VK_B] = SDLK_b; 327 VK_keymap[VK_K] = SDLK_k;
324 VK_keymap[VK_C] = SDLK_c; 328 VK_keymap[VK_L] = SDLK_l;
325 VK_keymap[VK_D] = SDLK_d; 329 VK_keymap[VK_M] = SDLK_m;
326 VK_keymap[VK_E] = SDLK_e; 330 VK_keymap[VK_N] = SDLK_n;
327 VK_keymap[VK_F] = SDLK_f; 331 VK_keymap[VK_O] = SDLK_o;
328 VK_keymap[VK_G] = SDLK_g; 332 VK_keymap[VK_P] = SDLK_p;
329 VK_keymap[VK_H] = SDLK_h; 333 VK_keymap[VK_Q] = SDLK_q;
330 VK_keymap[VK_I] = SDLK_i; 334 VK_keymap[VK_R] = SDLK_r;
331 VK_keymap[VK_J] = SDLK_j; 335 VK_keymap[VK_S] = SDLK_s;
332 VK_keymap[VK_K] = SDLK_k; 336 VK_keymap[VK_T] = SDLK_t;
333 VK_keymap[VK_L] = SDLK_l; 337 VK_keymap[VK_U] = SDLK_u;
334 VK_keymap[VK_M] = SDLK_m; 338 VK_keymap[VK_V] = SDLK_v;
335 VK_keymap[VK_N] = SDLK_n; 339 VK_keymap[VK_W] = SDLK_w;
336 VK_keymap[VK_O] = SDLK_o; 340 VK_keymap[VK_X] = SDLK_x;
337 VK_keymap[VK_P] = SDLK_p; 341 VK_keymap[VK_Y] = SDLK_y;
338 VK_keymap[VK_Q] = SDLK_q; 342 VK_keymap[VK_Z] = SDLK_z;
339 VK_keymap[VK_R] = SDLK_r; 343 VK_keymap[VK_DELETE] = SDLK_DELETE;
340 VK_keymap[VK_S] = SDLK_s; 344
341 VK_keymap[VK_T] = SDLK_t; 345 VK_keymap[VK_NUMPAD0] = SDLK_KP0;
342 VK_keymap[VK_U] = SDLK_u; 346 VK_keymap[VK_NUMPAD1] = SDLK_KP1;
343 VK_keymap[VK_V] = SDLK_v; 347 VK_keymap[VK_NUMPAD2] = SDLK_KP2;
344 VK_keymap[VK_W] = SDLK_w; 348 VK_keymap[VK_NUMPAD3] = SDLK_KP3;
345 VK_keymap[VK_X] = SDLK_x; 349 VK_keymap[VK_NUMPAD4] = SDLK_KP4;
346 VK_keymap[VK_Y] = SDLK_y; 350 VK_keymap[VK_NUMPAD5] = SDLK_KP5;
347 VK_keymap[VK_Z] = SDLK_z; 351 VK_keymap[VK_NUMPAD6] = SDLK_KP6;
348 VK_keymap[VK_DELETE] = SDLK_DELETE; 352 VK_keymap[VK_NUMPAD7] = SDLK_KP7;
349 353 VK_keymap[VK_NUMPAD8] = SDLK_KP8;
350 VK_keymap[VK_NUMPAD0] = SDLK_KP0; 354 VK_keymap[VK_NUMPAD9] = SDLK_KP9;
351 VK_keymap[VK_NUMPAD1] = SDLK_KP1; 355 VK_keymap[VK_DECIMAL] = SDLK_KP_PERIOD;
352 VK_keymap[VK_NUMPAD2] = SDLK_KP2; 356 VK_keymap[VK_DIVIDE] = SDLK_KP_DIVIDE;
353 VK_keymap[VK_NUMPAD3] = SDLK_KP3; 357 VK_keymap[VK_MULTIPLY] = SDLK_KP_MULTIPLY;
354 VK_keymap[VK_NUMPAD4] = SDLK_KP4; 358 VK_keymap[VK_SUBTRACT] = SDLK_KP_MINUS;
355 VK_keymap[VK_NUMPAD5] = SDLK_KP5; 359 VK_keymap[VK_ADD] = SDLK_KP_PLUS;
356 VK_keymap[VK_NUMPAD6] = SDLK_KP6; 360
357 VK_keymap[VK_NUMPAD7] = SDLK_KP7; 361 VK_keymap[VK_UP] = SDLK_UP;
358 VK_keymap[VK_NUMPAD8] = SDLK_KP8; 362 VK_keymap[VK_DOWN] = SDLK_DOWN;
359 VK_keymap[VK_NUMPAD9] = SDLK_KP9; 363 VK_keymap[VK_RIGHT] = SDLK_RIGHT;
360 VK_keymap[VK_DECIMAL] = SDLK_KP_PERIOD; 364 VK_keymap[VK_LEFT] = SDLK_LEFT;
361 VK_keymap[VK_DIVIDE] = SDLK_KP_DIVIDE; 365 VK_keymap[VK_INSERT] = SDLK_INSERT;
362 VK_keymap[VK_MULTIPLY] = SDLK_KP_MULTIPLY; 366 VK_keymap[VK_HOME] = SDLK_HOME;
363 VK_keymap[VK_SUBTRACT] = SDLK_KP_MINUS; 367 VK_keymap[VK_END] = SDLK_END;
364 VK_keymap[VK_ADD] = SDLK_KP_PLUS; 368 VK_keymap[VK_PRIOR] = SDLK_PAGEUP;
365 369 VK_keymap[VK_NEXT] = SDLK_PAGEDOWN;
366 VK_keymap[VK_UP] = SDLK_UP; 370
367 VK_keymap[VK_DOWN] = SDLK_DOWN; 371 VK_keymap[VK_F1] = SDLK_F1;
368 VK_keymap[VK_RIGHT] = SDLK_RIGHT; 372 VK_keymap[VK_F2] = SDLK_F2;
369 VK_keymap[VK_LEFT] = SDLK_LEFT; 373 VK_keymap[VK_F3] = SDLK_F3;
370 VK_keymap[VK_INSERT] = SDLK_INSERT; 374 VK_keymap[VK_F4] = SDLK_F4;
371 VK_keymap[VK_HOME] = SDLK_HOME; 375 VK_keymap[VK_F5] = SDLK_F5;
372 VK_keymap[VK_END] = SDLK_END; 376 VK_keymap[VK_F6] = SDLK_F6;
373 VK_keymap[VK_PRIOR] = SDLK_PAGEUP; 377 VK_keymap[VK_F7] = SDLK_F7;
374 VK_keymap[VK_NEXT] = SDLK_PAGEDOWN; 378 VK_keymap[VK_F8] = SDLK_F8;
375 379 VK_keymap[VK_F9] = SDLK_F9;
376 VK_keymap[VK_F1] = SDLK_F1; 380 VK_keymap[VK_F10] = SDLK_F10;
377 VK_keymap[VK_F2] = SDLK_F2; 381 VK_keymap[VK_F11] = SDLK_F11;
378 VK_keymap[VK_F3] = SDLK_F3; 382 VK_keymap[VK_F12] = SDLK_F12;
379 VK_keymap[VK_F4] = SDLK_F4; 383 VK_keymap[VK_F13] = SDLK_F13;
380 VK_keymap[VK_F5] = SDLK_F5; 384 VK_keymap[VK_F14] = SDLK_F14;
381 VK_keymap[VK_F6] = SDLK_F6; 385 VK_keymap[VK_F15] = SDLK_F15;
382 VK_keymap[VK_F7] = SDLK_F7; 386
383 VK_keymap[VK_F8] = SDLK_F8; 387 VK_keymap[VK_NUMLOCK] = SDLK_NUMLOCK;
384 VK_keymap[VK_F9] = SDLK_F9; 388 VK_keymap[VK_CAPITAL] = SDLK_CAPSLOCK;
385 VK_keymap[VK_F10] = SDLK_F10; 389 VK_keymap[VK_SCROLL] = SDLK_SCROLLOCK;
386 VK_keymap[VK_F11] = SDLK_F11; 390 VK_keymap[VK_RSHIFT] = SDLK_RSHIFT;
387 VK_keymap[VK_F12] = SDLK_F12; 391 VK_keymap[VK_LSHIFT] = SDLK_LSHIFT;
388 VK_keymap[VK_F13] = SDLK_F13; 392 VK_keymap[VK_RCONTROL] = SDLK_RCTRL;
389 VK_keymap[VK_F14] = SDLK_F14; 393 VK_keymap[VK_LCONTROL] = SDLK_LCTRL;
390 VK_keymap[VK_F15] = SDLK_F15; 394 VK_keymap[VK_RMENU] = SDLK_RALT;
391 395 VK_keymap[VK_LMENU] = SDLK_LALT;
392 VK_keymap[VK_NUMLOCK] = SDLK_NUMLOCK; 396 VK_keymap[VK_RWIN] = SDLK_RSUPER;
393 VK_keymap[VK_CAPITAL] = SDLK_CAPSLOCK; 397 VK_keymap[VK_LWIN] = SDLK_LSUPER;
394 VK_keymap[VK_SCROLL] = SDLK_SCROLLOCK; 398
395 VK_keymap[VK_RSHIFT] = SDLK_RSHIFT; 399 VK_keymap[VK_HELP] = SDLK_HELP;
396 VK_keymap[VK_LSHIFT] = SDLK_LSHIFT;
397 VK_keymap[VK_RCONTROL] = SDLK_RCTRL;
398 VK_keymap[VK_LCONTROL] = SDLK_LCTRL;
399 VK_keymap[VK_RMENU] = SDLK_RALT;
400 VK_keymap[VK_LMENU] = SDLK_LALT;
401 VK_keymap[VK_RWIN] = SDLK_RSUPER;
402 VK_keymap[VK_LWIN] = SDLK_LSUPER;
403
404 VK_keymap[VK_HELP] = SDLK_HELP;
405 #ifdef VK_PRINT 400 #ifdef VK_PRINT
406 VK_keymap[VK_PRINT] = SDLK_PRINT; 401 VK_keymap[VK_PRINT] = SDLK_PRINT;
407 #endif 402 #endif
408 VK_keymap[VK_SNAPSHOT] = SDLK_PRINT; 403 VK_keymap[VK_SNAPSHOT] = SDLK_PRINT;
409 VK_keymap[VK_CANCEL] = SDLK_BREAK; 404 VK_keymap[VK_CANCEL] = SDLK_BREAK;
410 VK_keymap[VK_APPS] = SDLK_MENU; 405 VK_keymap[VK_APPS] = SDLK_MENU;
411 } 406 }
412 407
413 #define EXTKEYPAD(keypad) ((scancode & 0x100)?(mvke):(keypad)) 408 static SDL_keysym *
414 409 TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym * keysym, int pressed)
415 static int SDL_MapVirtualKey(int scancode, int vkey) 410 {
416 { 411 /* Set the keysym information */
417 int mvke = MapVirtualKeyEx(scancode & 0xFF, 1, hLayoutUS); 412 keysym->scancode = (unsigned char) scancode;
418 413 keysym->sym = VK_keymap[vkey];
419 switch(vkey) { 414 keysym->mod = KMOD_NONE;
420 /* These are always correct */ 415 keysym->unicode = 0;
421 case VK_DIVIDE: 416 if (pressed && SDL_TranslateUNICODE) {
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
456 static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed)
457 {
458 /* Set the keysym information */
459 keysym->scancode = (unsigned char) scancode;
460 keysym->mod = KMOD_NONE;
461 keysym->unicode = 0;
462 if ( pressed && SDL_TranslateUNICODE ) {
463 #ifdef NO_GETKEYBOARDSTATE 417 #ifdef NO_GETKEYBOARDSTATE
464 /* Uh oh, better hope the vkey is close enough.. */ 418 /* Uh oh, better hope the vkey is close enough.. */
465 keysym->unicode = vkey; 419 keysym->unicode = vkey;
466 #else 420 #else
467 BYTE keystate[256]; 421 BYTE keystate[256];
468 Uint16 wchars[2]; 422 Uint16 wchars[2];
469 423
470 GetKeyboardState(keystate); 424 GetKeyboardState(keystate);
471 if (SDL_ToUnicode((UINT)vkey, scancode, keystate, wchars, sizeof(wchars)/sizeof(wchars[0]), 0) == 1) 425 if (SDL_ToUnicode
472 { 426 ((UINT) vkey, scancode, keystate, wchars,
473 keysym->unicode = wchars[0]; 427 sizeof(wchars) / sizeof(wchars[0]), 0) == 1) {
474 } 428 keysym->unicode = wchars[0];
429 }
475 #endif /* NO_GETKEYBOARDSTATE */ 430 #endif /* NO_GETKEYBOARDSTATE */
476 } 431 }
477 432 return (keysym);
478 if ((vkey == VK_RETURN) && (scancode & 0x100)) { 433 }
479 /* No VK_ code for the keypad enter key */ 434
480 keysym->sym = SDLK_KP_ENTER; 435 int
481 } 436 DIB_CreateWindow(_THIS)
482 else { 437 {
483 keysym->sym = VK_keymap[SDL_MapVirtualKey(scancode, vkey)]; 438 char *windowid = SDL_getenv("SDL_WINDOWID");
484 } 439
485 440 SDL_RegisterApp(NULL, 0, 0);
486 #if 0 441
487 { 442 SDL_windowid = (windowid != NULL);
488 HKL hLayoutCurrent = GetKeyboardLayout(0); 443 if (SDL_windowid) {
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
501 return(keysym);
502 }
503
504 int DIB_CreateWindow(_THIS)
505 {
506 char *windowid = SDL_getenv("SDL_WINDOWID");
507
508 SDL_RegisterApp(NULL, 0, 0);
509
510 SDL_windowid = (windowid != NULL);
511 if ( SDL_windowid ) {
512 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) 444 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
513 /* wince 2.1 does not have strtol */ 445 /* wince 2.1 does not have strtol */
514 wchar_t *windowid_t = SDL_malloc((SDL_strlen(windowid) + 1) * sizeof(wchar_t)); 446 wchar_t *windowid_t =
515 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, windowid, -1, windowid_t, SDL_strlen(windowid) + 1); 447 SDL_malloc((SDL_strlen(windowid) + 1) * sizeof(wchar_t));
516 SDL_Window = (HWND)wcstol(windowid_t, NULL, 0); 448 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, windowid, -1,
517 SDL_free(windowid_t); 449 windowid_t, SDL_strlen(windowid) + 1);
450 SDL_Window = (HWND) wcstol(windowid_t, NULL, 0);
451 SDL_free(windowid_t);
518 #else 452 #else
519 SDL_Window = (HWND)SDL_strtoull(windowid, NULL, 0); 453 SDL_Window = (HWND) SDL_strtoull(windowid, NULL, 0);
520 #endif 454 #endif
521 if ( SDL_Window == NULL ) { 455 if (SDL_Window == NULL) {
522 SDL_SetError("Couldn't get user specified window"); 456 SDL_SetError("Couldn't get user specified window");
523 return(-1); 457 return (-1);
524 } 458 }
525 459
526 /* DJM: we want all event's for the user specified 460 /* DJM: we want all event's for the user specified
527 window to be handled by SDL. 461 window to be handled by SDL.
528 */ 462 */
529 userWindowProc = (WNDPROCTYPE)GetWindowLongPtr(SDL_Window, GWLP_WNDPROC); 463 userWindowProc =
530 SetWindowLongPtr(SDL_Window, GWLP_WNDPROC, (LONG_PTR)WinMessage); 464 (WNDPROCTYPE) GetWindowLongPtr(SDL_Window, GWLP_WNDPROC);
531 } else { 465 SetWindowLongPtr(SDL_Window, GWLP_WNDPROC, (LONG_PTR) WinMessage);
532 SDL_Window = CreateWindow(SDL_Appname, SDL_Appname, 466 } else {
533 (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX), 467 SDL_Window = CreateWindow(SDL_Appname, SDL_Appname,
534 CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, SDL_Instance, NULL); 468 (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU
535 if ( SDL_Window == NULL ) { 469 | WS_MINIMIZEBOX), CW_USEDEFAULT,
536 SDL_SetError("Couldn't create window"); 470 CW_USEDEFAULT, 0, 0, NULL, NULL,
537 return(-1); 471 SDL_Instance, NULL);
538 } 472 if (SDL_Window == NULL) {
539 ShowWindow(SDL_Window, SW_HIDE); 473 SDL_SetError("Couldn't create window");
540 } 474 return (-1);
541 475 }
542 /* JC 14 Mar 2006 476 ShowWindow(SDL_Window, SW_HIDE);
543 Flush the message loop or this can cause big problems later 477 }
544 Especially if the user decides to use dialog boxes or assert()! 478
545 */ 479 /* JC 14 Mar 2006
546 WIN_FlushMessageQueue(); 480 Flush the message loop or this can cause big problems later
547 481 Especially if the user decides to use dialog boxes or assert()!
548 return(0); 482 */
549 } 483 WIN_FlushMessageQueue();
550 484
551 void DIB_DestroyWindow(_THIS) 485 return (0);
552 { 486 }
553 if ( SDL_windowid ) { 487
554 SetWindowLongPtr(SDL_Window, GWLP_WNDPROC, (LONG_PTR)userWindowProc); 488 void
555 } else { 489 DIB_DestroyWindow(_THIS)
556 DestroyWindow(SDL_Window); 490 {
557 } 491 if (SDL_windowid) {
558 SDL_UnregisterApp(); 492 SetWindowLongPtr(SDL_Window, GWLP_WNDPROC, (LONG_PTR) userWindowProc);
559 493 } else {
560 /* JC 14 Mar 2006 494 DestroyWindow(SDL_Window);
561 Flush the message loop or this can cause big problems later 495 }
562 Especially if the user decides to use dialog boxes or assert()! 496 SDL_UnregisterApp();
563 */ 497
564 WIN_FlushMessageQueue(); 498 /* JC 14 Mar 2006
565 } 499 Flush the message loop or this can cause big problems later
500 Especially if the user decides to use dialog boxes or assert()!
501 */
502 WIN_FlushMessageQueue();
503 }
504
505 /* vi: set ts=4 sw=4 expandtab: */