Skip to content

Latest commit

 

History

History
715 lines (638 loc) · 19.8 KB

SDL_dibevents.c

File metadata and controls

715 lines (638 loc) · 19.8 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Dec 8, 2008
Dec 8, 2008
3
Copyright (C) 1997-2009 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
Feb 25, 2006
Feb 25, 2006
24
25
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
Apr 26, 2001
Apr 26, 2001
26
Feb 10, 2006
Feb 10, 2006
27
#include "SDL_main.h"
Apr 26, 2001
Apr 26, 2001
28
29
#include "SDL_events.h"
#include "SDL_syswm.h"
Feb 16, 2006
Feb 16, 2006
30
31
32
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
#include "../wincommon/SDL_lowvideo.h"
Feb 16, 2009
Feb 16, 2009
33
#include "SDL_gapidibvideo.h"
Apr 26, 2001
Apr 26, 2001
34
35
#include "SDL_vkeys.h"
Feb 16, 2009
Feb 16, 2009
36
37
38
39
40
41
42
43
#ifdef SDL_VIDEO_DRIVER_GAPI
#include "../gapi/SDL_gapivideo.h"
#endif
#ifdef SDL_VIDEO_DRIVER_WINDIB
#include "SDL_dibvideo.h"
#endif
Apr 26, 2001
Apr 26, 2001
44
45
46
47
48
49
50
51
52
53
#ifndef WM_APP
#define WM_APP 0x8000
#endif
#ifdef _WIN32_WCE
#define NO_GETKEYBOARDSTATE
#endif
/* The translation table from a Microsoft VK keysym to a SDL keysym */
static SDLKey VK_keymap[SDLK_LAST];
Mar 6, 2006
Mar 6, 2006
54
static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed);
Feb 16, 2009
Feb 16, 2009
55
static SDLKey Arrows_keymap[4];
Apr 26, 2001
Apr 26, 2001
56
57
58
59
60
/* Masks for processing the windows KEYDOWN and KEYUP messages */
#define REPEATED_KEYMASK (1<<30)
#define EXTENDED_KEYMASK (1<<24)
Aug 9, 2001
Aug 9, 2001
61
62
/* DJM: If the user setup the window for us, we want to save his window proc,
and give him a chance to handle some messages. */
Jan 31, 2006
Jan 31, 2006
63
64
65
66
67
68
#ifdef STRICT
#define WNDPROCTYPE WNDPROC
#else
#define WNDPROCTYPE FARPROC
#endif
static WNDPROCTYPE userWindowProc = NULL;
Aug 9, 2001
Aug 9, 2001
69
Jan 19, 2006
Jan 19, 2006
70
Feb 16, 2009
Feb 16, 2009
71
#ifdef SDL_VIDEO_DRIVER_GAPI
Jan 19, 2006
Jan 19, 2006
72
Feb 16, 2009
Feb 16, 2009
73
WPARAM rotateKey(WPARAM key,int direction)
Jan 19, 2006
Jan 19, 2006
74
{
Feb 16, 2009
Feb 16, 2009
75
76
if(direction ==0 ) return key;
Jan 19, 2006
Jan 19, 2006
77
78
switch (key) {
case 0x26: /* up */
Feb 16, 2009
Feb 16, 2009
79
return Arrows_keymap[(2 + direction) % 4];
Jan 19, 2006
Jan 19, 2006
80
case 0x27: /* right */
Feb 16, 2009
Feb 16, 2009
81
return Arrows_keymap[(1 + direction) % 4];
Jan 19, 2006
Jan 19, 2006
82
case 0x28: /* down */
Feb 16, 2009
Feb 16, 2009
83
return Arrows_keymap[direction % 4];
Jan 19, 2006
Jan 19, 2006
84
case 0x25: /* left */
Feb 16, 2009
Feb 16, 2009
85
return Arrows_keymap[(3 + direction) % 4];
Jan 19, 2006
Jan 19, 2006
86
87
88
89
90
}
return key;
}
May 7, 2009
May 7, 2009
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* for gapi landscape mode */
static void GapiTransform(SDL_ScreenOrientation rotate, char hires, Sint16 *x, Sint16 *y) {
Sint16 rotatedX;
Sint16 rotatedY;
if (hires) {
*x = *x * 2;
*y = *y * 2;
}
switch(rotate) {
case SDL_ORIENTATION_UP:
{
/* this code needs testing on a real device!
So it will be enabled later */
/*
#ifdef _WIN32_WCE
#if _WIN32_WCE >= 420
// test device orientation
// FIXME: do not check every mouse message
DEVMODE settings;
SDL_memset(&settings, 0, sizeof(DEVMODE));
settings.dmSize = sizeof(DEVMODE);
settings.dmFields = DM_DISPLAYORIENTATION;
ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL);
if( settings.dmOrientation == DMDO_90 )
{
rotatedX = SDL_VideoSurface->h - *x;
rotatedY = *y;
*x = rotatedX;
*y = rotatedY;
}
#endif
#endif */
}
break;
// FIXME: Older version used just SDL_VideoSurface->(w, h)
// w and h are "clipped" while x and y are "raw", which caused
// x in former and y in latter case to be clipped in a wrong direction,
// thus offsetting the coordinate on 2 x clip pixels
// (like, 128 for 640 -> 512 clipping).
// We will now try to extract and use raw values.
// The way to do that RIGHT is do (orientation-dependent) clipping before
// doing this transform, but it's hardly possible.
// SEE SDL_mouse.c /ClipOffset to understand these calculations.
case SDL_ORIENTATION_RIGHT:
if (!SDL_VideoSurface)
break;
rotatedX = (2 * ((SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/
SDL_VideoSurface->format->BytesPerPixel))
+ SDL_VideoSurface->w - *y;
rotatedY = *x;
*x = rotatedX;
*y = rotatedY;
break;
case SDL_ORIENTATION_LEFT:
if (!SDL_VideoSurface)
break;
rotatedX = *y;
rotatedY = (2 * (SDL_VideoSurface->offset/SDL_VideoSurface->pitch))
+ SDL_VideoSurface->h - *x;
*x = rotatedX;
*y = rotatedY;
break;
}
}
Jan 19, 2006
Jan 19, 2006
159
160
161
#endif
Apr 26, 2001
Apr 26, 2001
162
/* The main Win32 event handler */
Mar 1, 2006
Mar 1, 2006
163
LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Apr 26, 2001
Apr 26, 2001
164
165
166
167
168
169
170
171
{
extern int posted;
switch (msg) {
case WM_SYSKEYDOWN:
case WM_KEYDOWN: {
SDL_keysym keysym;
Feb 16, 2009
Feb 16, 2009
172
173
174
175
176
177
#ifdef SDL_VIDEO_DRIVER_GAPI
if(this->hidden->gapiInfo)
{
// Drop GAPI artefacts
if (wParam == 0x84 || wParam == 0x5B)
return 0;
Jan 19, 2006
Jan 19, 2006
178
Feb 16, 2009
Feb 16, 2009
179
180
wParam = rotateKey(wParam, this->hidden->gapiInfo->coordinateTransform);
}
Jan 19, 2006
Jan 19, 2006
181
#endif
Apr 26, 2001
Apr 26, 2001
182
183
184
185
186
187
188
189
190
191
192
193
194
/* Ignore repeated keys */
if ( lParam&REPEATED_KEYMASK ) {
return(0);
}
switch (wParam) {
case VK_CONTROL:
if ( lParam&EXTENDED_KEYMASK )
wParam = VK_RCONTROL;
else
wParam = VK_LCONTROL;
break;
case VK_SHIFT:
/* EXTENDED trick doesn't work here */
Jan 29, 2006
Jan 29, 2006
195
196
197
{
Uint8 *state = SDL_GetKeyState(NULL);
if (state[SDLK_LSHIFT] == SDL_RELEASED && (GetKeyState(VK_LSHIFT) & 0x8000)) {
Dec 11, 2002
Dec 11, 2002
198
wParam = VK_LSHIFT;
Jan 29, 2006
Jan 29, 2006
199
} else if (state[SDLK_RSHIFT] == SDL_RELEASED && (GetKeyState(VK_RSHIFT) & 0x8000)) {
Dec 11, 2002
Dec 11, 2002
200
201
wParam = VK_RSHIFT;
} else {
May 18, 2006
May 18, 2006
202
203
204
205
206
207
208
209
210
211
/* Win9x */
int sc = HIWORD(lParam) & 0xFF;
if (sc == 0x2A)
wParam = VK_LSHIFT;
else
if (sc == 0x36)
wParam = VK_RSHIFT;
else
wParam = VK_LSHIFT;
Jan 29, 2006
Jan 29, 2006
212
}
Dec 11, 2002
Dec 11, 2002
213
}
Apr 26, 2001
Apr 26, 2001
214
215
216
217
218
219
220
221
break;
case VK_MENU:
if ( lParam&EXTENDED_KEYMASK )
wParam = VK_RMENU;
else
wParam = VK_LMENU;
break;
}
Jul 18, 2001
Jul 18, 2001
222
223
224
#ifdef NO_GETKEYBOARDSTATE
/* this is the workaround for the missing ToAscii() and ToUnicode() in CE (not necessary at KEYUP!) */
if ( SDL_TranslateUNICODE ) {
Aug 9, 2001
Aug 9, 2001
225
226
227
228
229
230
231
232
MSG m;
m.hwnd = hwnd;
m.message = msg;
m.wParam = wParam;
m.lParam = lParam;
m.time = 0;
if ( TranslateMessage(&m) && PeekMessage(&m, hwnd, 0, WM_USER, PM_NOREMOVE) && (m.message == WM_CHAR) ) {
Jul 18, 2001
Jul 18, 2001
233
234
235
236
237
GetMessage(&m, hwnd, 0, WM_USER);
wParam = m.wParam;
}
}
#endif /* NO_GETKEYBOARDSTATE */
Apr 26, 2001
Apr 26, 2001
238
239
240
241
242
243
244
245
246
posted = SDL_PrivateKeyboard(SDL_PRESSED,
TranslateKey(wParam,HIWORD(lParam),&keysym,1));
}
return(0);
case WM_SYSKEYUP:
case WM_KEYUP: {
SDL_keysym keysym;
Feb 16, 2009
Feb 16, 2009
247
248
249
250
251
252
253
254
255
#ifdef SDL_VIDEO_DRIVER_GAPI
if(this->hidden->gapiInfo)
{
// Drop GAPI artifacts
if (wParam == 0x84 || wParam == 0x5B)
return 0;
wParam = rotateKey(wParam, this->hidden->gapiInfo->coordinateTransform);
}
Jan 19, 2006
Jan 19, 2006
256
257
#endif
Apr 26, 2001
Apr 26, 2001
258
259
260
261
262
263
264
265
266
switch (wParam) {
case VK_CONTROL:
if ( lParam&EXTENDED_KEYMASK )
wParam = VK_RCONTROL;
else
wParam = VK_LCONTROL;
break;
case VK_SHIFT:
/* EXTENDED trick doesn't work here */
Jan 29, 2006
Jan 29, 2006
267
268
269
{
Uint8 *state = SDL_GetKeyState(NULL);
if (state[SDLK_LSHIFT] == SDL_PRESSED && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
Jan 20, 2003
Jan 20, 2003
270
wParam = VK_LSHIFT;
Jan 29, 2006
Jan 29, 2006
271
} else if (state[SDLK_RSHIFT] == SDL_PRESSED && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
Jan 20, 2003
Jan 20, 2003
272
273
wParam = VK_RSHIFT;
} else {
May 18, 2006
May 18, 2006
274
275
276
277
278
279
280
281
282
283
/* Win9x */
int sc = HIWORD(lParam) & 0xFF;
if (sc == 0x2A)
wParam = VK_LSHIFT;
else
if (sc == 0x36)
wParam = VK_RSHIFT;
else
wParam = VK_LSHIFT;
Jan 29, 2006
Jan 29, 2006
284
}
Jan 20, 2003
Jan 20, 2003
285
}
Apr 26, 2001
Apr 26, 2001
286
287
288
289
290
291
292
293
break;
case VK_MENU:
if ( lParam&EXTENDED_KEYMASK )
wParam = VK_RMENU;
else
wParam = VK_LMENU;
break;
}
Mar 14, 2006
Mar 14, 2006
294
295
296
297
298
/* Windows only reports keyup for print screen */
if ( wParam == VK_SNAPSHOT && SDL_GetKeyState(NULL)[SDLK_PRINT] == SDL_RELEASED ) {
posted = SDL_PrivateKeyboard(SDL_PRESSED,
TranslateKey(wParam,HIWORD(lParam),&keysym,1));
}
Apr 26, 2001
Apr 26, 2001
299
300
301
302
posted = SDL_PrivateKeyboard(SDL_RELEASED,
TranslateKey(wParam,HIWORD(lParam),&keysym,0));
}
return(0);
Sep 30, 2003
Sep 30, 2003
303
304
#if defined(SC_SCREENSAVE) && defined(SC_MONITORPOWER)
case WM_SYSCOMMAND: {
Jun 26, 2007
Jun 26, 2007
305
306
const DWORD val = (DWORD) (wParam & 0xFFF0);
if ((val == SC_SCREENSAVE) || (val == SC_MONITORPOWER)) {
Feb 16, 2009
Feb 16, 2009
307
if (this->hidden->dibInfo && !allow_screensaver) {
Jun 26, 2007
Jun 26, 2007
308
309
/* Note that this doesn't stop anything on Vista
if the screensaver has a password. */
Sep 30, 2003
Sep 30, 2003
310
return(0);
Jun 26, 2007
Jun 26, 2007
311
312
}
}
Sep 30, 2003
Sep 30, 2003
313
314
315
316
}
/* Fall through to default processing */
#endif /* SC_SCREENSAVE && SC_MONITORPOWER */
Apr 26, 2001
Apr 26, 2001
317
318
319
320
321
322
323
324
325
326
327
default: {
/* Only post the event if we're watching for it */
if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
SDL_SysWMmsg wmmsg;
SDL_VERSION(&wmmsg.version);
wmmsg.hwnd = hwnd;
wmmsg.msg = msg;
wmmsg.wParam = wParam;
wmmsg.lParam = lParam;
posted = SDL_PrivateSysWMEvent(&wmmsg);
Aug 9, 2001
Aug 9, 2001
328
329
330
331
332
333
/* DJM: If the user isn't watching for private
messages in her SDL event loop, then pass it
along to any win32 specific window proc.
*/
} else if (userWindowProc) {
Sep 21, 2003
Sep 21, 2003
334
return CallWindowProc(userWindowProc, hwnd, msg, wParam, lParam);
Apr 26, 2001
Apr 26, 2001
335
336
337
338
339
340
341
}
}
break;
}
return(DefWindowProc(hwnd, msg, wParam, lParam));
}
May 7, 2009
May 7, 2009
342
static void DIB_GenerateMouseMotionEvent(_THIS)
Apr 2, 2009
Apr 2, 2009
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
{
extern int mouse_relative;
extern int posted;
POINT mouse;
GetCursorPos( &mouse );
if ( mouse_relative ) {
POINT center;
center.x = (SDL_VideoSurface->w/2);
center.y = (SDL_VideoSurface->h/2);
ClientToScreen(SDL_Window, &center);
mouse.x -= (Sint16)center.x;
mouse.y -= (Sint16)center.y;
if ( mouse.x || mouse.y ) {
SetCursorPos(center.x, center.y);
posted = SDL_PrivateMouseMotion(0, 1, mouse.x, mouse.y);
}
} else if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
ScreenToClient(SDL_Window, &mouse);
May 7, 2009
May 7, 2009
364
365
366
#ifdef SDL_VIDEO_DRIVER_GAPI
if (SDL_VideoSurface && this->hidden->gapiInfo)
GapiTransform(this->hidden->gapiInfo->coordinateTransform, this->hidden->gapiInfo->hiresFix, &mouse.x, &mouse.y);
Apr 2, 2009
Apr 2, 2009
367
368
369
370
371
#endif
posted = SDL_PrivateMouseMotion(0, 0, mouse.x, mouse.y);
}
}
Apr 26, 2001
Apr 26, 2001
372
373
374
375
void DIB_PumpEvents(_THIS)
{
MSG msg;
Oct 8, 2002
Oct 8, 2002
376
377
while ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) {
if ( GetMessage(&msg, NULL, 0, 0) > 0 ) {
Apr 26, 2001
Apr 26, 2001
378
379
380
DispatchMessage(&msg);
}
}
Apr 2, 2009
Apr 2, 2009
381
382
if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
May 7, 2009
May 7, 2009
383
DIB_GenerateMouseMotionEvent( this );
Apr 2, 2009
Apr 2, 2009
384
}
Apr 26, 2001
Apr 26, 2001
385
386
}
May 18, 2006
May 18, 2006
387
388
static HKL hLayoutUS = NULL;
Apr 26, 2001
Apr 26, 2001
389
390
void DIB_InitOSKeymap(_THIS)
{
May 18, 2006
May 18, 2006
391
int i;
Sep 23, 2006
Sep 23, 2006
392
393
#ifndef _WIN32_WCE
char current_layout[KL_NAMELENGTH];
May 18, 2006
May 18, 2006
394
395
396
397
398
GetKeyboardLayoutName(current_layout);
//printf("Initial Keyboard Layout Name: '%s'\n", current_layout);
hLayoutUS = LoadKeyboardLayout("00000409", KLF_NOTELLSHELL);
Sep 23, 2006
Sep 23, 2006
399
May 18, 2006
May 18, 2006
400
401
402
403
404
if (!hLayoutUS) {
//printf("Failed to load US keyboard layout. Using current.\n");
hLayoutUS = GetKeyboardLayout(0);
}
LoadKeyboardLayout(current_layout, KLF_ACTIVATE);
Sep 23, 2006
Sep 23, 2006
405
406
407
#else
#if _WIN32_WCE >=420
TCHAR current_layout[KL_NAMELENGTH];
Apr 26, 2001
Apr 26, 2001
408
Sep 23, 2006
Sep 23, 2006
409
410
411
412
413
414
415
416
417
418
419
420
GetKeyboardLayoutName(current_layout);
//printf("Initial Keyboard Layout Name: '%s'\n", current_layout);
hLayoutUS = LoadKeyboardLayout(L"00000409", 0);
if (!hLayoutUS) {
//printf("Failed to load US keyboard layout. Using current.\n");
hLayoutUS = GetKeyboardLayout(0);
}
LoadKeyboardLayout(current_layout, 0);
#endif // _WIN32_WCE >=420
#endif
Apr 26, 2001
Apr 26, 2001
421
/* Map the VK keysyms */
Feb 19, 2006
Feb 19, 2006
422
for ( i=0; i<SDL_arraysize(VK_keymap); ++i )
Apr 26, 2001
Apr 26, 2001
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
VK_keymap[i] = SDLK_UNKNOWN;
VK_keymap[VK_BACK] = SDLK_BACKSPACE;
VK_keymap[VK_TAB] = SDLK_TAB;
VK_keymap[VK_CLEAR] = SDLK_CLEAR;
VK_keymap[VK_RETURN] = SDLK_RETURN;
VK_keymap[VK_PAUSE] = SDLK_PAUSE;
VK_keymap[VK_ESCAPE] = SDLK_ESCAPE;
VK_keymap[VK_SPACE] = SDLK_SPACE;
VK_keymap[VK_APOSTROPHE] = SDLK_QUOTE;
VK_keymap[VK_COMMA] = SDLK_COMMA;
VK_keymap[VK_MINUS] = SDLK_MINUS;
VK_keymap[VK_PERIOD] = SDLK_PERIOD;
VK_keymap[VK_SLASH] = SDLK_SLASH;
VK_keymap[VK_0] = SDLK_0;
VK_keymap[VK_1] = SDLK_1;
VK_keymap[VK_2] = SDLK_2;
VK_keymap[VK_3] = SDLK_3;
VK_keymap[VK_4] = SDLK_4;
VK_keymap[VK_5] = SDLK_5;
VK_keymap[VK_6] = SDLK_6;
VK_keymap[VK_7] = SDLK_7;
VK_keymap[VK_8] = SDLK_8;
VK_keymap[VK_9] = SDLK_9;
VK_keymap[VK_SEMICOLON] = SDLK_SEMICOLON;
VK_keymap[VK_EQUALS] = SDLK_EQUALS;
VK_keymap[VK_LBRACKET] = SDLK_LEFTBRACKET;
VK_keymap[VK_BACKSLASH] = SDLK_BACKSLASH;
Jan 19, 2006
Jan 19, 2006
451
VK_keymap[VK_OEM_102] = SDLK_LESS;
Apr 26, 2001
Apr 26, 2001
452
453
VK_keymap[VK_RBRACKET] = SDLK_RIGHTBRACKET;
VK_keymap[VK_GRAVE] = SDLK_BACKQUOTE;
Mar 31, 2002
Mar 31, 2002
454
VK_keymap[VK_BACKTICK] = SDLK_BACKQUOTE;
Apr 26, 2001
Apr 26, 2001
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
VK_keymap[VK_A] = SDLK_a;
VK_keymap[VK_B] = SDLK_b;
VK_keymap[VK_C] = SDLK_c;
VK_keymap[VK_D] = SDLK_d;
VK_keymap[VK_E] = SDLK_e;
VK_keymap[VK_F] = SDLK_f;
VK_keymap[VK_G] = SDLK_g;
VK_keymap[VK_H] = SDLK_h;
VK_keymap[VK_I] = SDLK_i;
VK_keymap[VK_J] = SDLK_j;
VK_keymap[VK_K] = SDLK_k;
VK_keymap[VK_L] = SDLK_l;
VK_keymap[VK_M] = SDLK_m;
VK_keymap[VK_N] = SDLK_n;
VK_keymap[VK_O] = SDLK_o;
VK_keymap[VK_P] = SDLK_p;
VK_keymap[VK_Q] = SDLK_q;
VK_keymap[VK_R] = SDLK_r;
VK_keymap[VK_S] = SDLK_s;
VK_keymap[VK_T] = SDLK_t;
VK_keymap[VK_U] = SDLK_u;
VK_keymap[VK_V] = SDLK_v;
VK_keymap[VK_W] = SDLK_w;
VK_keymap[VK_X] = SDLK_x;
VK_keymap[VK_Y] = SDLK_y;
VK_keymap[VK_Z] = SDLK_z;
VK_keymap[VK_DELETE] = SDLK_DELETE;
VK_keymap[VK_NUMPAD0] = SDLK_KP0;
VK_keymap[VK_NUMPAD1] = SDLK_KP1;
VK_keymap[VK_NUMPAD2] = SDLK_KP2;
VK_keymap[VK_NUMPAD3] = SDLK_KP3;
VK_keymap[VK_NUMPAD4] = SDLK_KP4;
VK_keymap[VK_NUMPAD5] = SDLK_KP5;
VK_keymap[VK_NUMPAD6] = SDLK_KP6;
VK_keymap[VK_NUMPAD7] = SDLK_KP7;
VK_keymap[VK_NUMPAD8] = SDLK_KP8;
VK_keymap[VK_NUMPAD9] = SDLK_KP9;
VK_keymap[VK_DECIMAL] = SDLK_KP_PERIOD;
VK_keymap[VK_DIVIDE] = SDLK_KP_DIVIDE;
VK_keymap[VK_MULTIPLY] = SDLK_KP_MULTIPLY;
VK_keymap[VK_SUBTRACT] = SDLK_KP_MINUS;
VK_keymap[VK_ADD] = SDLK_KP_PLUS;
VK_keymap[VK_UP] = SDLK_UP;
VK_keymap[VK_DOWN] = SDLK_DOWN;
VK_keymap[VK_RIGHT] = SDLK_RIGHT;
VK_keymap[VK_LEFT] = SDLK_LEFT;
VK_keymap[VK_INSERT] = SDLK_INSERT;
VK_keymap[VK_HOME] = SDLK_HOME;
VK_keymap[VK_END] = SDLK_END;
VK_keymap[VK_PRIOR] = SDLK_PAGEUP;
VK_keymap[VK_NEXT] = SDLK_PAGEDOWN;
VK_keymap[VK_F1] = SDLK_F1;
VK_keymap[VK_F2] = SDLK_F2;
VK_keymap[VK_F3] = SDLK_F3;
VK_keymap[VK_F4] = SDLK_F4;
VK_keymap[VK_F5] = SDLK_F5;
VK_keymap[VK_F6] = SDLK_F6;
VK_keymap[VK_F7] = SDLK_F7;
VK_keymap[VK_F8] = SDLK_F8;
VK_keymap[VK_F9] = SDLK_F9;
VK_keymap[VK_F10] = SDLK_F10;
VK_keymap[VK_F11] = SDLK_F11;
VK_keymap[VK_F12] = SDLK_F12;
VK_keymap[VK_F13] = SDLK_F13;
VK_keymap[VK_F14] = SDLK_F14;
VK_keymap[VK_F15] = SDLK_F15;
VK_keymap[VK_NUMLOCK] = SDLK_NUMLOCK;
VK_keymap[VK_CAPITAL] = SDLK_CAPSLOCK;
VK_keymap[VK_SCROLL] = SDLK_SCROLLOCK;
VK_keymap[VK_RSHIFT] = SDLK_RSHIFT;
VK_keymap[VK_LSHIFT] = SDLK_LSHIFT;
VK_keymap[VK_RCONTROL] = SDLK_RCTRL;
VK_keymap[VK_LCONTROL] = SDLK_LCTRL;
VK_keymap[VK_RMENU] = SDLK_RALT;
VK_keymap[VK_LMENU] = SDLK_LALT;
VK_keymap[VK_RWIN] = SDLK_RSUPER;
VK_keymap[VK_LWIN] = SDLK_LSUPER;
VK_keymap[VK_HELP] = SDLK_HELP;
#ifdef VK_PRINT
VK_keymap[VK_PRINT] = SDLK_PRINT;
#endif
VK_keymap[VK_SNAPSHOT] = SDLK_PRINT;
VK_keymap[VK_CANCEL] = SDLK_BREAK;
VK_keymap[VK_APPS] = SDLK_MENU;
Feb 16, 2009
Feb 16, 2009
544
545
546
547
548
Arrows_keymap[3] = 0x25;
Arrows_keymap[2] = 0x26;
Arrows_keymap[1] = 0x27;
Arrows_keymap[0] = 0x28;
Apr 26, 2001
Apr 26, 2001
549
550
}
May 18, 2006
May 18, 2006
551
552
553
554
#define EXTKEYPAD(keypad) ((scancode & 0x100)?(mvke):(keypad))
static int SDL_MapVirtualKey(int scancode, int vkey)
{
Sep 23, 2006
Sep 23, 2006
555
#ifndef _WIN32_WCE
May 18, 2006
May 18, 2006
556
int mvke = MapVirtualKeyEx(scancode & 0xFF, 1, hLayoutUS);
Sep 23, 2006
Sep 23, 2006
557
558
559
#else
int mvke = MapVirtualKey(scancode & 0xFF, 1);
#endif
May 18, 2006
May 18, 2006
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
switch(vkey) {
/* These are always correct */
case VK_DIVIDE:
case VK_MULTIPLY:
case VK_SUBTRACT:
case VK_ADD:
case VK_LWIN:
case VK_RWIN:
case VK_APPS:
/* These are already handled */
case VK_LCONTROL:
case VK_RCONTROL:
case VK_LSHIFT:
case VK_RSHIFT:
case VK_LMENU:
case VK_RMENU:
case VK_SNAPSHOT:
case VK_PAUSE:
return vkey;
}
switch(mvke) {
/* Distinguish between keypad and extended keys */
case VK_INSERT: return EXTKEYPAD(VK_NUMPAD0);
case VK_DELETE: return EXTKEYPAD(VK_DECIMAL);
case VK_END: return EXTKEYPAD(VK_NUMPAD1);
case VK_DOWN: return EXTKEYPAD(VK_NUMPAD2);
case VK_NEXT: return EXTKEYPAD(VK_NUMPAD3);
case VK_LEFT: return EXTKEYPAD(VK_NUMPAD4);
case VK_CLEAR: return EXTKEYPAD(VK_NUMPAD5);
case VK_RIGHT: return EXTKEYPAD(VK_NUMPAD6);
case VK_HOME: return EXTKEYPAD(VK_NUMPAD7);
case VK_UP: return EXTKEYPAD(VK_NUMPAD8);
case VK_PRIOR: return EXTKEYPAD(VK_NUMPAD9);
}
return mvke?mvke:vkey;
}
Mar 6, 2006
Mar 6, 2006
598
static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed)
Apr 26, 2001
Apr 26, 2001
599
600
601
602
603
{
/* Set the keysym information */
keysym->scancode = (unsigned char) scancode;
keysym->mod = KMOD_NONE;
keysym->unicode = 0;
Feb 16, 2009
Feb 16, 2009
604
605
606
607
608
609
610
611
612
if ((vkey == VK_RETURN) && (scancode & 0x100)) {
/* No VK_ code for the keypad enter key */
keysym->sym = SDLK_KP_ENTER;
}
else {
keysym->sym = VK_keymap[SDL_MapVirtualKey(scancode, vkey)];
}
Jan 19, 2006
Jan 19, 2006
613
if ( pressed && SDL_TranslateUNICODE ) {
Apr 26, 2001
Apr 26, 2001
614
615
#ifdef NO_GETKEYBOARDSTATE
/* Uh oh, better hope the vkey is close enough.. */
Feb 16, 2009
Feb 16, 2009
616
if((keysym->sym == vkey) || (vkey > 0x7f))
Apr 26, 2001
Apr 26, 2001
617
618
keysym->unicode = vkey;
#else
Jan 19, 2006
Jan 19, 2006
619
620
BYTE keystate[256];
Uint16 wchars[2];
Apr 26, 2001
Apr 26, 2001
621
622
GetKeyboardState(keystate);
Apr 13, 2009
Apr 13, 2009
623
624
625
626
627
628
629
/* Numlock isn't taken into account in ToUnicode,
* so we handle it as a special case here */
if ((keystate[VK_NUMLOCK] & 1) && vkey >= VK_NUMPAD0 && vkey <= VK_NUMPAD9)
{
keysym->unicode = vkey - VK_NUMPAD0 + '0';
}
else if (SDL_ToUnicode((UINT)vkey, scancode, keystate, wchars, sizeof(wchars)/sizeof(wchars[0]), 0) > 0)
Jan 19, 2006
Jan 19, 2006
630
631
{
keysym->unicode = wchars[0];
Apr 26, 2001
Apr 26, 2001
632
633
634
}
#endif /* NO_GETKEYBOARDSTATE */
}
May 18, 2006
May 18, 2006
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
#if 0
{
HKL hLayoutCurrent = GetKeyboardLayout(0);
int sc = scancode & 0xFF;
printf("SYM:%d, VK:0x%02X, SC:0x%04X, US:(1:0x%02X, 3:0x%02X), "
"Current:(1:0x%02X, 3:0x%02X)\n",
keysym->sym, vkey, scancode,
MapVirtualKeyEx(sc, 1, hLayoutUS),
MapVirtualKeyEx(sc, 3, hLayoutUS),
MapVirtualKeyEx(sc, 1, hLayoutCurrent),
MapVirtualKeyEx(sc, 3, hLayoutCurrent)
);
}
#endif
Apr 26, 2001
Apr 26, 2001
651
652
653
654
655
return(keysym);
}
int DIB_CreateWindow(_THIS)
{
Feb 7, 2006
Feb 7, 2006
656
char *windowid = SDL_getenv("SDL_WINDOWID");
Sep 29, 2005
Sep 29, 2005
657
Jan 29, 2006
Jan 29, 2006
658
SDL_RegisterApp(NULL, 0, 0);
Sep 29, 2005
Sep 29, 2005
659
Jan 29, 2006
Jan 29, 2006
660
661
SDL_windowid = (windowid != NULL);
if ( SDL_windowid ) {
Sep 29, 2005
Sep 29, 2005
662
#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
Jan 29, 2006
Jan 29, 2006
663
/* wince 2.1 does not have strtol */
Feb 7, 2006
Feb 7, 2006
664
665
wchar_t *windowid_t = SDL_malloc((SDL_strlen(windowid) + 1) * sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, windowid, -1, windowid_t, SDL_strlen(windowid) + 1);
Jan 29, 2006
Jan 29, 2006
666
SDL_Window = (HWND)wcstol(windowid_t, NULL, 0);
Feb 7, 2006
Feb 7, 2006
667
SDL_free(windowid_t);
Sep 29, 2005
Sep 29, 2005
668
#else
Mar 1, 2006
Mar 1, 2006
669
SDL_Window = (HWND)SDL_strtoull(windowid, NULL, 0);
Sep 29, 2005
Sep 29, 2005
670
#endif
Nov 15, 2004
Nov 15, 2004
671
672
673
674
675
676
677
678
if ( SDL_Window == NULL ) {
SDL_SetError("Couldn't get user specified window");
return(-1);
}
/* DJM: we want all event's for the user specified
window to be handled by SDL.
*/
Mar 6, 2006
Mar 6, 2006
679
680
userWindowProc = (WNDPROCTYPE)GetWindowLongPtr(SDL_Window, GWLP_WNDPROC);
SetWindowLongPtr(SDL_Window, GWLP_WNDPROC, (LONG_PTR)WinMessage);
Apr 26, 2001
Apr 26, 2001
681
682
683
} else {
SDL_Window = CreateWindow(SDL_Appname, SDL_Appname,
(WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX),
Feb 16, 2004
Feb 16, 2004
684
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, SDL_Instance, NULL);
Apr 26, 2001
Apr 26, 2001
685
686
687
688
689
690
if ( SDL_Window == NULL ) {
SDL_SetError("Couldn't create window");
return(-1);
}
ShowWindow(SDL_Window, SW_HIDE);
}
Mar 14, 2006
Mar 14, 2006
691
692
693
694
695
696
697
/* JC 14 Mar 2006
Flush the message loop or this can cause big problems later
Especially if the user decides to use dialog boxes or assert()!
*/
WIN_FlushMessageQueue();
Apr 26, 2001
Apr 26, 2001
698
699
700
701
702
return(0);
}
void DIB_DestroyWindow(_THIS)
{
Nov 15, 2004
Nov 15, 2004
703
if ( SDL_windowid ) {
Mar 6, 2006
Mar 6, 2006
704
SetWindowLongPtr(SDL_Window, GWLP_WNDPROC, (LONG_PTR)userWindowProc);
Nov 15, 2004
Nov 15, 2004
705
} else {
Apr 26, 2001
Apr 26, 2001
706
707
DestroyWindow(SDL_Window);
}
Jan 29, 2006
Jan 29, 2006
708
SDL_UnregisterApp();
Mar 14, 2006
Mar 14, 2006
709
710
711
712
713
714
/* JC 14 Mar 2006
Flush the message loop or this can cause big problems later
Especially if the user decides to use dialog boxes or assert()!
*/
WIN_FlushMessageQueue();
Apr 26, 2001
Apr 26, 2001
715
}