Mercurial > sdl-ios-xcode
annotate src/video/windx5/SDL_dx5events.c @ 4384:6800e2560310 SDL-1.2
Fixed bugs #882 and 865, re-opening bug #634
Ronald Lamprecht to SDL
Hi,
Sam Lantinga wrote:
The problem with that fix is that it breaks IME events again. Maybe
we can handle keyboard events differently to prevent this issue?
Spending an hour reading MSDN, analysing SDL and another hour testing the reality on XP I am really wondering how patch r4990 could have ever worked in any situation. It's main effect is to break the unicode translation and causing spurious activation events!
Why does TranslateMessage(&msg) nothing useful? Simply because it does not affect "msg" at all! All keyboard events are dispatched without the slightest change (see MSDN). TranslateMessage() just appends additional WM_CHAR, WM_DEADCHAR, WM_SYSCHAR, WM_SYSDEADCHAR event messages to the queue. But I could not find any SDL event handling routine that catches these events and transforms them to proper SDL keyevents while eliminating the corresponding WM_KEYDOWN, etc. events. Thus any IME input like the '@' generated by "Alt + 6(Numpad) + 4(Numpad)" is simply lost.
But the situation is even worse! Up to r4990 the TranslateKey()/ToUnicode() calls did evaluate dead keys and did deliver proper key events for subsequent key strokes like '´' + 'e' resulting in 'é'. ToUnicode() needs proper key state informations to be able to handle these substitutions. But unfortunatly TranslateMessage() needs the same state information and eats it up while generating the WM_CHAR messages :-( Thus the current 1.2.14 breakes the partial IME support of previous releases, too.
The key state race condition between ToUnicode() and TranslateMessage() requires to avoid any ToUnicode() usage for receiving proper WM_CHAR, etc. messages generated by TranslateMessage(). (Yes - the '@' and 'é' appear as WM_CHAR messages when unicode is switched off).
The spurious SDL activation events are *not* caused by additional WM_ACTIVATE Windows messages! Besides DIB_HandleMessage() SDL_PrivateAppActive() is called by another source which I am not yet aware of - any hints?
Thus I do strongly recommend the deletion of the TranslateMessage(&msg) call as a quick fix.
A proper support of unicode and IME requires a clean SDL keyboard input concept first. Which SDL keyboards events should be transmitted to the app when the user presses '´' + 'e' ? Within the current unicode handling the first key stroke is hidden. Even though ToUnicode() delivers the proper key SDL does ignore it in TranslateKey(). Just the composed key event is transmitted to the app. That is what you expect for text input, but the app can no longer use keys like '^' as a key button because it will never receive a key event for it!
With a given concept it seems to be necessary to regenerate SDL key events out of the WM_CHAR, etc. events and to drop all related direct WM_KEYDOWN, etc. events while the remaining basic WM_KEYDOWN, etc. events would still have to result in SDL key events.
Anyway the source of the spurious WM_ACTIVATE should be located to avoid future trouble.
Greets,
Ronald
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 17 Nov 2009 04:59:13 +0000 |
parents | daf9e6037596 |
children | 07b330419439 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
4159 | 3 Copyright (C) 1997-2009 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1303
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1303
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1303
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1303
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1303
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1303
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* CAUTION!!!! If you modify this file, check ../windib/SDL_sysevents.c */ | |
25 | |
26 #include "directx.h" | |
27 | |
1358
c71e05b4dc2e
More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents:
1348
diff
changeset
|
28 #include "SDL_main.h" |
0 | 29 #include "SDL_events.h" |
30 #include "SDL_video.h" | |
31 #include "SDL_syswm.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
32 #include "../../events/SDL_sysevents.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
33 #include "../../events/SDL_events_c.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
34 #include "../wincommon/SDL_lowvideo.h" |
0 | 35 #include "SDL_dx5video.h" |
36 | |
37 #ifndef WM_APP | |
38 #define WM_APP 0x8000 | |
39 #endif | |
40 | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
41 #ifdef _WIN32_WCE |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
42 #define NO_GETKEYBOARDSTATE |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
43 #endif |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
44 |
0 | 45 /* The keyboard and mouse device input */ |
4237
0adda8ff43ef
Potentially fixed bug #774
Sam Lantinga <slouken@libsdl.org>
parents:
4191
diff
changeset
|
46 #define MAX_INPUTS 2 |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
47 #define INPUT_QSIZE 512 /* Buffer up to 512 input messages */ |
0 | 48 |
49 static LPDIRECTINPUT dinput = NULL; | |
50 static LPDIRECTINPUTDEVICE2 SDL_DIdev[MAX_INPUTS]; | |
51 static HANDLE SDL_DIevt[MAX_INPUTS]; | |
52 static void (*SDL_DIfun[MAX_INPUTS])(const int, DIDEVICEOBJECTDATA *); | |
53 static int SDL_DIndev = 0; | |
54 static int mouse_lost; | |
55 static int mouse_pressed; | |
491
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
56 static int mouse_buttons_swapped = 0; |
0 | 57 |
58 /* The translation table from a DirectInput scancode to an SDL keysym */ | |
59 static SDLKey DIK_keymap[256]; | |
60 static SDL_keysym *TranslateKey(UINT scancode, SDL_keysym *keysym, int pressed); | |
61 | |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
62 /* DJM: If the user setup the window for us, we want to save his window proc, |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
63 and give him a chance to handle some messages. */ |
1303
52b5afd7ecee
Date: Tue, 05 Jul 2005 21:43:26 +1000
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
64 #ifdef STRICT |
52b5afd7ecee
Date: Tue, 05 Jul 2005 21:43:26 +1000
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
65 #define WNDPROCTYPE WNDPROC |
52b5afd7ecee
Date: Tue, 05 Jul 2005 21:43:26 +1000
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
66 #else |
52b5afd7ecee
Date: Tue, 05 Jul 2005 21:43:26 +1000
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
67 #define WNDPROCTYPE FARPROC |
52b5afd7ecee
Date: Tue, 05 Jul 2005 21:43:26 +1000
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
68 #endif |
52b5afd7ecee
Date: Tue, 05 Jul 2005 21:43:26 +1000
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
69 static WNDPROCTYPE userWindowProc = NULL; |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
70 |
1114
242a35a85852
Patches to make SDL compatible with Win95 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
975
diff
changeset
|
71 static HWND GetTopLevelParent(HWND hWnd) |
242a35a85852
Patches to make SDL compatible with Win95 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
975
diff
changeset
|
72 { |
242a35a85852
Patches to make SDL compatible with Win95 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
975
diff
changeset
|
73 HWND hParentWnd; |
242a35a85852
Patches to make SDL compatible with Win95 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
975
diff
changeset
|
74 while (1) |
242a35a85852
Patches to make SDL compatible with Win95 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
975
diff
changeset
|
75 { |
242a35a85852
Patches to make SDL compatible with Win95 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
975
diff
changeset
|
76 hParentWnd = GetParent(hWnd); |
242a35a85852
Patches to make SDL compatible with Win95 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
975
diff
changeset
|
77 if (hParentWnd == NULL) |
242a35a85852
Patches to make SDL compatible with Win95 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
975
diff
changeset
|
78 break; |
242a35a85852
Patches to make SDL compatible with Win95 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
975
diff
changeset
|
79 hWnd = hParentWnd; |
242a35a85852
Patches to make SDL compatible with Win95 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
975
diff
changeset
|
80 } |
242a35a85852
Patches to make SDL compatible with Win95 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
975
diff
changeset
|
81 return hWnd; |
242a35a85852
Patches to make SDL compatible with Win95 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
975
diff
changeset
|
82 } |
242a35a85852
Patches to make SDL compatible with Win95 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
975
diff
changeset
|
83 |
0 | 84 /* Convert a DirectInput return code to a text message */ |
85 static void SetDIerror(char *function, int code) | |
86 { | |
87 static char *error; | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
88 static char errbuf[1024]; |
0 | 89 |
90 errbuf[0] = 0; | |
91 switch (code) { | |
92 case DIERR_GENERIC: | |
93 error = "Undefined error!"; | |
94 break; | |
95 case DIERR_OLDDIRECTINPUTVERSION: | |
96 error = "Your version of DirectInput needs upgrading"; | |
97 break; | |
98 case DIERR_INVALIDPARAM: | |
99 error = "Invalid parameters"; | |
100 break; | |
101 case DIERR_OUTOFMEMORY: | |
102 error = "Out of memory"; | |
103 break; | |
104 case DIERR_DEVICENOTREG: | |
105 error = "Device not registered"; | |
106 break; | |
107 case DIERR_NOINTERFACE: | |
108 error = "Interface not supported"; | |
109 break; | |
110 case DIERR_NOTINITIALIZED: | |
111 error = "Device not initialized"; | |
112 break; | |
113 default: | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
114 SDL_snprintf(errbuf, SDL_arraysize(errbuf), |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
115 "%s: Unknown DirectInput error: 0x%x", |
0 | 116 function, code); |
117 break; | |
118 } | |
119 if ( ! errbuf[0] ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
120 SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error); |
0 | 121 } |
122 SDL_SetError("%s", errbuf); | |
123 return; | |
124 } | |
125 | |
126 /* Initialize DirectInput | |
127 Note: If NONEXCLUSIVE access is requested for the devices, normal | |
128 windows input messages will continue to be generated for that | |
129 input device, in addition to DirectInput messages. | |
130 */ | |
131 static void handle_keyboard(const int numevents, DIDEVICEOBJECTDATA *events); | |
132 static void handle_mouse(const int numevents, DIDEVICEOBJECTDATA *events); | |
133 struct { | |
134 char *name; | |
135 REFGUID guid; | |
136 LPCDIDATAFORMAT format; | |
137 DWORD win_level; | |
138 DWORD raw_level; | |
139 void (*fun)(const int numevents, DIDEVICEOBJECTDATA *events); | |
140 } inputs[] = { | |
141 { "keyboard", | |
142 &GUID_SysKeyboard, &c_dfDIKeyboard, | |
143 (DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), | |
144 (DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), handle_keyboard }, | |
145 { "mouse", | |
4167 | 146 &GUID_SysMouse, |
147 #if DIRECTINPUT_VERSION >= 0x700 | |
148 &c_dfDIMouse2, | |
149 #else | |
150 &c_dfDIMouse, | |
151 #endif | |
0 | 152 (DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), |
4167 | 153 (DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), handle_mouse }, |
0 | 154 { NULL, NULL, NULL, 0, 0, NULL } |
155 }; | |
156 | |
157 static int DX5_DInputInit(_THIS) | |
158 { | |
159 int i; | |
160 LPDIRECTINPUTDEVICE device; | |
161 HRESULT result; | |
162 DIPROPDWORD dipdw; | |
970
fb8b91365766
Date: Tue, 19 Oct 2004 23:04:58 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
833
diff
changeset
|
163 HWND topwnd; |
0 | 164 |
165 /* Create the DirectInput object */ | |
166 result = DInputCreate(SDL_Instance, DIRECTINPUT_VERSION, | |
167 &dinput, NULL); | |
168 if ( result != DI_OK ) { | |
169 SetDIerror("DirectInputCreate", result); | |
170 return(-1); | |
171 } | |
172 | |
173 /* Create all of our registered input devices */ | |
174 SDL_DIndev = 0; | |
175 for ( i=0; inputs[i].name; ++i ) { | |
176 /* Create the DirectInput device */ | |
177 result = IDirectInput_CreateDevice(dinput, inputs[i].guid, | |
178 &device, NULL); | |
179 if ( result != DI_OK ) { | |
180 SetDIerror("DirectInput::CreateDevice", result); | |
181 return(-1); | |
182 } | |
183 result = IDirectInputDevice_QueryInterface(device, | |
184 &IID_IDirectInputDevice2, (LPVOID *)&SDL_DIdev[i]); | |
185 IDirectInputDevice_Release(device); | |
186 if ( result != DI_OK ) { | |
187 SetDIerror("DirectInputDevice::QueryInterface", result); | |
188 return(-1); | |
189 } | |
1115
040aa1bea9fc
Fixed mismerged patch.
Ryan C. Gordon <icculus@icculus.org>
parents:
1114
diff
changeset
|
190 topwnd = GetTopLevelParent(SDL_Window); |
0 | 191 result = IDirectInputDevice2_SetCooperativeLevel(SDL_DIdev[i], |
970
fb8b91365766
Date: Tue, 19 Oct 2004 23:04:58 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
833
diff
changeset
|
192 topwnd, inputs[i].win_level); |
0 | 193 if ( result != DI_OK ) { |
194 SetDIerror("DirectInputDevice::SetCooperativeLevel", | |
195 result); | |
196 return(-1); | |
197 } | |
198 result = IDirectInputDevice2_SetDataFormat(SDL_DIdev[i], | |
199 inputs[i].format); | |
200 if ( result != DI_OK ) { | |
201 SetDIerror("DirectInputDevice::SetDataFormat", result); | |
202 return(-1); | |
203 } | |
204 | |
205 /* Set buffered input -- we aren't polling */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
206 SDL_memset(&dipdw, 0, sizeof(dipdw)); |
0 | 207 dipdw.diph.dwSize = sizeof(dipdw); |
208 dipdw.diph.dwHeaderSize = sizeof(dipdw.diph); | |
209 dipdw.diph.dwObj = 0; | |
210 dipdw.diph.dwHow = DIPH_DEVICE; | |
211 dipdw.dwData = INPUT_QSIZE; | |
212 result = IDirectInputDevice2_SetProperty(SDL_DIdev[i], | |
213 DIPROP_BUFFERSIZE, &dipdw.diph); | |
214 if ( result != DI_OK ) { | |
215 SetDIerror("DirectInputDevice::SetProperty", result); | |
216 return(-1); | |
217 } | |
218 | |
219 /* Create an event to be signaled when input is ready */ | |
220 SDL_DIevt[i] = CreateEvent(NULL, FALSE, FALSE, NULL); | |
221 if ( SDL_DIevt[i] == NULL ) { | |
222 SDL_SetError("Couldn't create DirectInput event"); | |
223 return(-1); | |
224 } | |
225 result = IDirectInputDevice2_SetEventNotification(SDL_DIdev[i], | |
226 SDL_DIevt[i]); | |
227 if ( result != DI_OK ) { | |
228 SetDIerror("DirectInputDevice::SetEventNotification", | |
229 result); | |
230 return(-1); | |
231 } | |
232 SDL_DIfun[i] = inputs[i].fun; | |
233 | |
234 /* Acquire the device for input */ | |
235 IDirectInputDevice2_Acquire(SDL_DIdev[i]); | |
236 | |
237 /* Increment the number of devices we have */ | |
238 ++SDL_DIndev; | |
239 } | |
240 mouse_pressed = 0; | |
491
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
241 mouse_buttons_swapped = GetSystemMetrics(SM_SWAPBUTTON); |
0 | 242 |
243 /* DirectInput is ready! */ | |
244 return(0); | |
245 } | |
246 | |
247 /* Clean up DirectInput */ | |
248 static void DX5_DInputQuit(_THIS) | |
249 { | |
250 int i; | |
251 | |
252 if ( dinput != NULL ) { | |
253 /* Close and release all DirectInput devices */ | |
254 for ( i=0; i<MAX_INPUTS; ++i ) { | |
255 if ( SDL_DIdev[i] != NULL ) { | |
256 IDirectInputDevice2_Unacquire(SDL_DIdev[i]); | |
257 IDirectInputDevice2_SetEventNotification( | |
258 SDL_DIdev[i], NULL); | |
259 if ( SDL_DIevt[i] != NULL ) { | |
260 CloseHandle(SDL_DIevt[i]); | |
261 SDL_DIevt[i] = NULL; | |
262 } | |
263 IDirectInputDevice2_Release(SDL_DIdev[i]); | |
264 SDL_DIdev[i] = NULL; | |
265 } | |
266 } | |
4237
0adda8ff43ef
Potentially fixed bug #774
Sam Lantinga <slouken@libsdl.org>
parents:
4191
diff
changeset
|
267 SDL_DIndev = 0; |
0adda8ff43ef
Potentially fixed bug #774
Sam Lantinga <slouken@libsdl.org>
parents:
4191
diff
changeset
|
268 |
0 | 269 /* Release DirectInput */ |
270 IDirectInput_Release(dinput); | |
271 dinput = NULL; | |
272 } | |
273 } | |
274 | |
275 /* Flag to tell SDL whether or not we queued an event */ | |
276 static int posted = 0; | |
277 | |
278 /* Input event handler functions */ | |
279 static void handle_keyboard(const int numevents, DIDEVICEOBJECTDATA *keybuf) | |
280 { | |
281 int i; | |
282 SDL_keysym keysym; | |
283 | |
284 /* Translate keyboard messages */ | |
285 for ( i=0; i<numevents; ++i ) { | |
286 if ( keybuf[i].dwData & 0x80 ) { | |
287 posted = SDL_PrivateKeyboard(SDL_PRESSED, | |
288 TranslateKey(keybuf[i].dwOfs, &keysym, 1)); | |
289 } else { | |
290 posted = SDL_PrivateKeyboard(SDL_RELEASED, | |
291 TranslateKey(keybuf[i].dwOfs, &keysym, 0)); | |
292 } | |
293 } | |
294 } | |
4167 | 295 |
296 static void post_mouse_motion(int relative, Sint16 x, Sint16 y) | |
297 { | |
298 extern int mouse_relative; | |
299 | |
4191
caaa3cbf7b13
Put some extra parentheses around some logic, to clarify order of operations.
Ryan C. Gordon <icculus@icculus.org>
parents:
4171
diff
changeset
|
300 if ( (SDL_GetAppState() & (SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS)) == |
4167 | 301 (SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS) ) { |
302 posted = SDL_PrivateMouseMotion( | |
303 0, relative, x, y); | |
304 | |
305 if ( !mouse_relative ) { | |
306 /* As DirectInput reads raw device coordinates, it has no notion of | |
307 * cursors or absolute position. We must assume responsibility for | |
308 * keeping track of this. */ | |
309 int current_x, current_y; | |
310 POINT cursor; | |
311 RECT trap; | |
312 RECT window; | |
313 int at_edge; | |
314 | |
315 /* Get the current cursor position */ | |
316 SDL_GetMouseState(¤t_x, ¤t_y); | |
317 cursor.x = current_x; | |
318 cursor.y = current_y; | |
319 ClientToScreen(SDL_Window, &cursor); | |
320 | |
321 /* Construct a 1 pixel square RECT that is used to confine the cursor | |
322 * pointer to a specific pixel using ClipCursor. This is used in | |
323 * preference to SetCursorPos as it avoids the cursor jumping around as | |
324 * both the OS and SDL attempt to move it simultaneously. */ | |
325 trap.left = cursor.x; | |
326 trap.top = cursor.y; | |
327 trap.right = cursor.x + 1; | |
328 trap.bottom = cursor.y + 1; | |
329 | |
330 GetClientRect(SDL_Window, &window); | |
331 window.right -= window.left; window.left = 0; | |
332 window.bottom -= window.top; window.top = 0; | |
333 | |
334 /* As we're assuming control over the cursor, we need to know when to | |
335 * relinquish control of it back to the operating system. This is when | |
336 * the cursor reaches the edge of the window. */ | |
337 at_edge = (current_x == window.left) || | |
338 (current_x == (window.right - 1)) || | |
339 (current_y == window.top) || | |
340 (current_y == (window.bottom - 1)); | |
341 | |
342 if ( at_edge ) { | |
343 ClipCursor(NULL); | |
344 } else { | |
345 ClipCursor(&trap); | |
346 } | |
347 } else { | |
348 /* When in relative mode, warp the OS's idea of where the cursor is to | |
349 * the center of the screen. This isn't really necessary as DirectInput | |
350 * reads from the hardware itself, but in case things go wrong, the | |
351 * cursor will be left in a sensible place. */ | |
352 POINT center; | |
353 center.x = (SDL_VideoSurface->w/2); | |
354 center.y = (SDL_VideoSurface->h/2); | |
355 ClientToScreen(SDL_Window, ¢er); | |
356 SetCursorPos(center.x, center.y); | |
357 } | |
358 } else { | |
359 /* No window or mouse focus, control is lost */ | |
360 mouse_lost = 1; | |
361 ClipCursor(NULL); | |
362 } | |
363 } | |
364 | |
0 | 365 static void handle_mouse(const int numevents, DIDEVICEOBJECTDATA *ptrbuf) |
366 { | |
367 int i; | |
368 Sint16 xrel, yrel; | |
369 Uint8 state; | |
370 Uint8 button; | |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
371 DWORD timestamp = 0; |
0 | 372 |
717
42ed44b2c8b6
Date: Sun, 14 Sep 2003 17:04:55 -0400
Ryan C. Gordon <icculus@icculus.org>
parents:
536
diff
changeset
|
373 /* Sanity check. Mailing list reports this being NULL unexpectedly. */ |
42ed44b2c8b6
Date: Sun, 14 Sep 2003 17:04:55 -0400
Ryan C. Gordon <icculus@icculus.org>
parents:
536
diff
changeset
|
374 if (SDL_PublicSurface == NULL) { |
42ed44b2c8b6
Date: Sun, 14 Sep 2003 17:04:55 -0400
Ryan C. Gordon <icculus@icculus.org>
parents:
536
diff
changeset
|
375 return; |
42ed44b2c8b6
Date: Sun, 14 Sep 2003 17:04:55 -0400
Ryan C. Gordon <icculus@icculus.org>
parents:
536
diff
changeset
|
376 } |
42ed44b2c8b6
Date: Sun, 14 Sep 2003 17:04:55 -0400
Ryan C. Gordon <icculus@icculus.org>
parents:
536
diff
changeset
|
377 |
0 | 378 /* If the mouse was lost, regain some sense of mouse state */ |
4167 | 379 if ( mouse_lost && (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) { |
0 | 380 POINT mouse_pos; |
381 Uint8 old_state; | |
382 Uint8 new_state; | |
383 | |
384 /* Set ourselves up with the current cursor position */ | |
385 GetCursorPos(&mouse_pos); | |
386 ScreenToClient(SDL_Window, &mouse_pos); | |
4167 | 387 post_mouse_motion( 0, (Sint16)mouse_pos.x, (Sint16)mouse_pos.y); |
0 | 388 |
389 /* Check for mouse button changes */ | |
390 old_state = SDL_GetMouseState(NULL, NULL); | |
391 new_state = 0; | |
392 { /* Get the new DirectInput button state for the mouse */ | |
4167 | 393 #if DIRECTINPUT_VERSION >= 0x700 |
394 DIMOUSESTATE2 distate; | |
395 #else | |
0 | 396 DIMOUSESTATE distate; |
4167 | 397 #endif |
0 | 398 HRESULT result; |
399 | |
400 result=IDirectInputDevice2_GetDeviceState(SDL_DIdev[1], | |
401 sizeof(distate), &distate); | |
402 if ( result != DI_OK ) { | |
403 /* Try again next time */ | |
404 SetDIerror( | |
405 "IDirectInputDevice2::GetDeviceState", result); | |
406 return; | |
407 } | |
408 for ( i=3; i>=0; --i ) { | |
409 if ( (distate.rgbButtons[i]&0x80) == 0x80 ) { | |
410 new_state |= 0x01; | |
411 } | |
412 new_state <<= 1; | |
413 } | |
414 } | |
415 for ( i=0; i<8; ++i ) { | |
416 if ( (old_state&0x01) != (new_state&0x01) ) { | |
417 button = (Uint8)(i+1); | |
4167 | 418 /* Map DI button numbers to SDL */ |
419 switch ( button ) { | |
420 case 2: button = SDL_BUTTON_RIGHT; break; | |
421 case 3: button = SDL_BUTTON_MIDDLE; break; | |
422 case 4: button = SDL_BUTTON_X1; break; | |
423 case 5: button = SDL_BUTTON_X2; break; | |
424 default: break; | |
0 | 425 } |
426 if ( new_state & 0x01 ) { | |
427 /* Grab mouse so we get mouse-up */ | |
428 if ( ++mouse_pressed > 0 ) { | |
429 SetCapture(SDL_Window); | |
430 } | |
431 state = SDL_PRESSED; | |
432 } else { | |
433 /* Release mouse after all mouse-ups */ | |
434 if ( --mouse_pressed <= 0 ) { | |
435 ReleaseCapture(); | |
436 mouse_pressed = 0; | |
437 } | |
438 state = SDL_RELEASED; | |
439 } | |
491
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
440 if ( mouse_buttons_swapped ) { |
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
441 if ( button == 1 ) button = 3; |
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
442 else |
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
443 if ( button == 3 ) button = 1; |
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
444 } |
0 | 445 posted = SDL_PrivateMouseButton(state, button, |
446 0, 0); | |
447 } | |
448 old_state >>= 1; | |
449 new_state >>= 1; | |
450 } | |
451 mouse_lost = 0; | |
452 return; | |
453 } | |
454 | |
455 /* Translate mouse messages */ | |
456 xrel = 0; | |
457 yrel = 0; | |
458 for ( i=0; i<(int)numevents; ++i ) { | |
459 switch (ptrbuf[i].dwOfs) { | |
460 case DIMOFS_X: | |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
461 if ( timestamp != ptrbuf[i].dwTimeStamp ) { |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
462 if ( xrel || yrel ) { |
4167 | 463 post_mouse_motion(1, xrel, yrel); |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
464 xrel = 0; |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
465 yrel = 0; |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
466 } |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
467 timestamp = ptrbuf[i].dwTimeStamp; |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
468 } |
0 | 469 xrel += (Sint16)ptrbuf[i].dwData; |
470 break; | |
471 case DIMOFS_Y: | |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
472 if ( timestamp != ptrbuf[i].dwTimeStamp ) { |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
473 if ( xrel || yrel ) { |
4167 | 474 post_mouse_motion(1, xrel, yrel); |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
475 xrel = 0; |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
476 yrel = 0; |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
477 } |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
478 timestamp = ptrbuf[i].dwTimeStamp; |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
479 } |
0 | 480 yrel += (Sint16)ptrbuf[i].dwData; |
481 break; | |
61
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
482 case DIMOFS_Z: |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
483 if ( xrel || yrel ) { |
4167 | 484 post_mouse_motion(1, xrel, yrel); |
61
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
485 xrel = 0; |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
486 yrel = 0; |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
487 } |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
488 timestamp = 0; |
61
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
489 if((int)ptrbuf[i].dwData > 0) |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
490 button = SDL_BUTTON_WHEELUP; |
332 | 491 else |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
492 button = SDL_BUTTON_WHEELDOWN; |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
493 posted = SDL_PrivateMouseButton( |
332 | 494 SDL_PRESSED, button, 0, 0); |
495 posted |= SDL_PrivateMouseButton( | |
496 SDL_RELEASED, button, 0, 0); | |
61
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
497 break; |
0 | 498 case DIMOFS_BUTTON0: |
499 case DIMOFS_BUTTON1: | |
500 case DIMOFS_BUTTON2: | |
501 case DIMOFS_BUTTON3: | |
4167 | 502 #if DIRECTINPUT_VERSION >= 0x700 |
503 case DIMOFS_BUTTON4: | |
504 case DIMOFS_BUTTON5: | |
505 case DIMOFS_BUTTON6: | |
506 case DIMOFS_BUTTON7: | |
507 #endif | |
0 | 508 if ( xrel || yrel ) { |
4167 | 509 post_mouse_motion(1, xrel, yrel); |
0 | 510 xrel = 0; |
511 yrel = 0; | |
512 } | |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
513 timestamp = 0; |
0 | 514 button = (Uint8)(ptrbuf[i].dwOfs-DIMOFS_BUTTON0)+1; |
4167 | 515 /* Map DI button numbers to SDL */ |
516 switch ( button ) { | |
517 case 2: button = SDL_BUTTON_RIGHT; break; | |
518 case 3: button = SDL_BUTTON_MIDDLE; break; | |
519 case 4: button = SDL_BUTTON_X1; break; | |
520 case 5: button = SDL_BUTTON_X2; break; | |
521 default: break; | |
0 | 522 } |
523 if ( ptrbuf[i].dwData & 0x80 ) { | |
524 /* Grab mouse so we get mouse-up */ | |
525 if ( ++mouse_pressed > 0 ) { | |
526 SetCapture(SDL_Window); | |
527 } | |
528 state = SDL_PRESSED; | |
529 } else { | |
530 /* Release mouse after all mouse-ups */ | |
531 if ( --mouse_pressed <= 0 ) { | |
532 ReleaseCapture(); | |
533 mouse_pressed = 0; | |
534 } | |
535 state = SDL_RELEASED; | |
536 } | |
491
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
537 if ( mouse_buttons_swapped ) { |
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
538 if ( button == 1 ) button = 3; |
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
539 else |
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
540 if ( button == 3 ) button = 1; |
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
541 } |
0 | 542 posted = SDL_PrivateMouseButton(state, button, |
543 0, 0); | |
544 break; | |
545 } | |
546 } | |
547 if ( xrel || yrel ) { | |
4167 | 548 post_mouse_motion(1, xrel, yrel); |
0 | 549 } |
550 } | |
551 | |
552 /* The main Win32 event handler */ | |
1456
84de7511f79f
Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
553 LRESULT DX5_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
0 | 554 { |
555 switch (msg) { | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
556 #ifdef WM_ACTIVATEAPP |
0 | 557 case WM_ACTIVATEAPP: { |
558 int i, active; | |
559 | |
560 active = (wParam && (GetForegroundWindow() == hwnd)); | |
561 if ( active ) { | |
4383 | 562 for ( i=0; i<MAX_INPUTS; ++i ) { |
563 if (SDL_DIdev[i] != NULL) | |
564 IDirectInputDevice2_Acquire( | |
0 | 565 SDL_DIdev[i]); |
566 } | |
567 } else { | |
4383 | 568 for ( i=0; i<MAX_INPUTS; ++i ) { |
569 if (SDL_DIdev[i] != NULL) | |
570 IDirectInputDevice2_Unacquire( | |
0 | 571 SDL_DIdev[i]); |
572 } | |
573 mouse_lost = 1; | |
574 } | |
575 } | |
576 break; | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
577 #endif /* WM_ACTIVATEAPP */ |
0 | 578 |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
579 #ifdef WM_DISPLAYCHANGE |
0 | 580 case WM_DISPLAYCHANGE: { |
1456
84de7511f79f
Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
581 WPARAM BitsPerPixel; |
0 | 582 WORD SizeX, SizeY; |
583 | |
584 /* Ack! The display changed size and/or depth! */ | |
585 SizeX = LOWORD(lParam); | |
586 SizeY = HIWORD(lParam); | |
587 BitsPerPixel = wParam; | |
588 /* We cause this message when we go fullscreen */ | |
589 } | |
590 break; | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
591 #endif /* WM_DISPLAYCHANGE */ |
0 | 592 |
593 /* The keyboard is handled via DirectInput */ | |
594 case WM_SYSKEYUP: | |
4171 | 595 case WM_SYSKEYDOWN: |
0 | 596 case WM_KEYUP: |
597 case WM_KEYDOWN: { | |
598 /* Ignore windows keyboard messages */; | |
599 } | |
600 return(0); | |
601 | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
602 #if defined(SC_SCREENSAVE) || defined(SC_MONITORPOWER) |
0 | 603 /* Don't allow screen savers or monitor power downs. |
604 This is because they quietly clear DirectX surfaces. | |
605 It would be better to allow the application to | |
606 decide whether or not to blow these off, but the | |
607 semantics of SDL_PrivateSysWMEvent() don't allow | |
608 the application that choice. | |
609 */ | |
610 case WM_SYSCOMMAND: { | |
611 if ((wParam&0xFFF0)==SC_SCREENSAVE || | |
612 (wParam&0xFFF0)==SC_MONITORPOWER) | |
613 return(0); | |
614 } | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
615 /* Fall through to default processing */ |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
616 |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
617 #endif /* SC_SCREENSAVE || SC_MONITORPOWER */ |
0 | 618 |
619 default: { | |
620 /* Only post the event if we're watching for it */ | |
621 if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { | |
622 SDL_SysWMmsg wmmsg; | |
623 | |
624 SDL_VERSION(&wmmsg.version); | |
625 wmmsg.hwnd = hwnd; | |
626 wmmsg.msg = msg; | |
627 wmmsg.wParam = wParam; | |
628 wmmsg.lParam = lParam; | |
629 posted = SDL_PrivateSysWMEvent(&wmmsg); | |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
630 |
721
ab0656314eef
Date: Thu, 18 Sep 2003 14:24:35 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
717
diff
changeset
|
631 /* DJM: If the user isn't watching for private |
ab0656314eef
Date: Thu, 18 Sep 2003 14:24:35 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
717
diff
changeset
|
632 messages in her SDL event loop, then pass it |
ab0656314eef
Date: Thu, 18 Sep 2003 14:24:35 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
717
diff
changeset
|
633 along to any win32 specific window proc. |
ab0656314eef
Date: Thu, 18 Sep 2003 14:24:35 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
717
diff
changeset
|
634 */ |
ab0656314eef
Date: Thu, 18 Sep 2003 14:24:35 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
717
diff
changeset
|
635 } else if (userWindowProc) { |
ab0656314eef
Date: Thu, 18 Sep 2003 14:24:35 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
717
diff
changeset
|
636 return CallWindowProc(userWindowProc, hwnd, msg, wParam, lParam); |
ab0656314eef
Date: Thu, 18 Sep 2003 14:24:35 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
717
diff
changeset
|
637 } |
0 | 638 } |
639 break; | |
640 } | |
641 return(DefWindowProc(hwnd, msg, wParam, lParam)); | |
642 } | |
643 | |
644 /* This function checks the windows message queue and DirectInput and returns | |
645 1 if there was input, 0 if there was no input, or -1 if the application has | |
646 posted a quit message. | |
647 */ | |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
648 static int DX5_CheckInput(_THIS, int timeout, BOOL processInput) |
0 | 649 { |
650 MSG msg; | |
651 int i; | |
652 HRESULT result; | |
653 DWORD event; | |
654 | |
655 /* Check the normal windows queue (highest preference) */ | |
656 posted = 0; | |
657 while ( ! posted && | |
523
c210010f50f4
Fixed windows event handling for ActiveX controls (thanks Huib-Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
491
diff
changeset
|
658 PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { |
c210010f50f4
Fixed windows event handling for ActiveX controls (thanks Huib-Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
491
diff
changeset
|
659 if ( GetMessage(&msg, NULL, 0, 0) > 0 ) { |
0 | 660 DispatchMessage(&msg); |
661 } else { | |
662 return(-1); | |
663 } | |
664 } | |
665 if ( posted ) { | |
666 return(1); | |
667 } | |
668 | |
669 /* Pump the DirectInput flow */ | |
670 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
4237
0adda8ff43ef
Potentially fixed bug #774
Sam Lantinga <slouken@libsdl.org>
parents:
4191
diff
changeset
|
671 for ( i=0; i<MAX_INPUTS; ++i ) { |
0adda8ff43ef
Potentially fixed bug #774
Sam Lantinga <slouken@libsdl.org>
parents:
4191
diff
changeset
|
672 if ( SDL_DIdev[i] != NULL ) { |
0adda8ff43ef
Potentially fixed bug #774
Sam Lantinga <slouken@libsdl.org>
parents:
4191
diff
changeset
|
673 result = IDirectInputDevice2_Poll(SDL_DIdev[i]); |
0adda8ff43ef
Potentially fixed bug #774
Sam Lantinga <slouken@libsdl.org>
parents:
4191
diff
changeset
|
674 if ( (result == DIERR_INPUTLOST) || |
0adda8ff43ef
Potentially fixed bug #774
Sam Lantinga <slouken@libsdl.org>
parents:
4191
diff
changeset
|
675 (result == DIERR_NOTACQUIRED) ) { |
0adda8ff43ef
Potentially fixed bug #774
Sam Lantinga <slouken@libsdl.org>
parents:
4191
diff
changeset
|
676 if ( SDL_strcmp(inputs[i].name, "mouse") == 0 ) { |
0adda8ff43ef
Potentially fixed bug #774
Sam Lantinga <slouken@libsdl.org>
parents:
4191
diff
changeset
|
677 mouse_lost = 1; |
0adda8ff43ef
Potentially fixed bug #774
Sam Lantinga <slouken@libsdl.org>
parents:
4191
diff
changeset
|
678 } |
0adda8ff43ef
Potentially fixed bug #774
Sam Lantinga <slouken@libsdl.org>
parents:
4191
diff
changeset
|
679 IDirectInputDevice2_Acquire(SDL_DIdev[i]); |
0adda8ff43ef
Potentially fixed bug #774
Sam Lantinga <slouken@libsdl.org>
parents:
4191
diff
changeset
|
680 IDirectInputDevice2_Poll(SDL_DIdev[i]); |
0 | 681 } |
682 } | |
683 } | |
684 } | |
685 | |
686 /* Wait for messages and input events */ | |
687 event = MsgWaitForMultipleObjects(SDL_DIndev, SDL_DIevt, FALSE, | |
688 timeout, QS_ALLEVENTS); | |
689 if ((event >= WAIT_OBJECT_0) && (event < (WAIT_OBJECT_0+SDL_DIndev))) { | |
690 DWORD numevents; | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
691 static DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE]; |
0 | 692 |
693 event -= WAIT_OBJECT_0; | |
694 numevents = INPUT_QSIZE; | |
695 result = IDirectInputDevice2_GetDeviceData( | |
696 SDL_DIdev[event], sizeof(DIDEVICEOBJECTDATA), | |
697 evtbuf, &numevents, 0); | |
698 if ( (result == DIERR_INPUTLOST) || | |
699 (result == DIERR_NOTACQUIRED) ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
700 if ( SDL_strcmp(inputs[event].name, "mouse") == 0 ) { |
0 | 701 mouse_lost = 1; |
702 } | |
703 IDirectInputDevice2_Acquire(SDL_DIdev[event]); | |
704 result = IDirectInputDevice2_GetDeviceData( | |
705 SDL_DIdev[event], sizeof(DIDEVICEOBJECTDATA), | |
706 evtbuf, &numevents, 0); | |
707 } | |
708 /* Handle the events */ | |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
709 if ( result == DI_OK && processInput ) { |
0 | 710 /* Note: This can post multiple events to event queue |
711 */ | |
712 (*SDL_DIfun[event])((int)numevents, evtbuf); | |
713 return(1); | |
714 } | |
715 } | |
716 if ( event != WAIT_TIMEOUT ) { | |
717 /* Maybe there was a windows message? */ | |
4384
6800e2560310
Fixed bugs #882 and 865, re-opening bug #634
Sam Lantinga <slouken@libsdl.org>
parents:
4383
diff
changeset
|
718 if ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { |
0 | 719 if ( GetMessage(&msg, NULL, 0, 0) > 0 ) { |
720 DispatchMessage(&msg); | |
721 } else { | |
722 return(-1); | |
723 } | |
724 return(1); | |
725 } | |
726 } | |
727 return(0); | |
728 } | |
729 | |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
730 /* Change cooperative level based on whether or not we are fullscreen */ |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
731 void DX5_DInputReset(_THIS, int fullscreen) |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
732 { |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
733 DWORD level; |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
734 int i; |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
735 HRESULT result; |
970
fb8b91365766
Date: Tue, 19 Oct 2004 23:04:58 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
833
diff
changeset
|
736 HWND topwnd; |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
737 |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
738 for ( i=0; i<MAX_INPUTS; ++i ) { |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
739 if ( SDL_DIdev[i] != NULL ) { |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
740 if ( fullscreen ) { |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
741 level = inputs[i].raw_level; |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
742 } else { |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
743 level = inputs[i].win_level; |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
744 } |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
745 IDirectInputDevice2_Unacquire(SDL_DIdev[i]); |
1115
040aa1bea9fc
Fixed mismerged patch.
Ryan C. Gordon <icculus@icculus.org>
parents:
1114
diff
changeset
|
746 topwnd = GetTopLevelParent(SDL_Window); |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
747 result = IDirectInputDevice2_SetCooperativeLevel( |
970
fb8b91365766
Date: Tue, 19 Oct 2004 23:04:58 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
833
diff
changeset
|
748 SDL_DIdev[i], topwnd, level); |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
749 IDirectInputDevice2_Acquire(SDL_DIdev[i]); |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
750 if ( result != DI_OK ) { |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
751 SetDIerror( |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
752 "DirectInputDevice::SetCooperativeLevel", result); |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
753 } |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
754 } |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
755 } |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
756 mouse_lost = 1; |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
757 |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
758 /* Flush pending input */ |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
759 DX5_CheckInput(this, 0, FALSE); |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
760 } |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
761 |
0 | 762 void DX5_PumpEvents(_THIS) |
763 { | |
764 /* Wait for messages and DirectInput */ | |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
765 while ( DX5_CheckInput(this, 0, TRUE) > 0 ) { |
0 | 766 /* Loop and check again */; |
767 } | |
768 } | |
769 | |
770 void DX5_InitOSKeymap(_THIS) | |
771 { | |
275
53fc686e9428
Added support for the pause key under DirectX
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
772 #ifndef DIK_PAUSE |
53fc686e9428
Added support for the pause key under DirectX
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
773 #define DIK_PAUSE 0xC5 |
53fc686e9428
Added support for the pause key under DirectX
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
774 #endif |
327
13fc64213765
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
325
diff
changeset
|
775 #ifndef DIK_OEM_102 |
13fc64213765
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
325
diff
changeset
|
776 #define DIK_OEM_102 0x56 /* < > | on UK/Germany keyboards */ |
13fc64213765
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
325
diff
changeset
|
777 #endif |
0 | 778 int i; |
779 | |
780 /* Map the DIK scancodes to SDL keysyms */ | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
781 for ( i=0; i<SDL_arraysize(DIK_keymap); ++i ) |
0 | 782 DIK_keymap[i] = 0; |
783 | |
784 /* Defined DIK_* constants */ | |
785 DIK_keymap[DIK_ESCAPE] = SDLK_ESCAPE; | |
786 DIK_keymap[DIK_1] = SDLK_1; | |
787 DIK_keymap[DIK_2] = SDLK_2; | |
788 DIK_keymap[DIK_3] = SDLK_3; | |
789 DIK_keymap[DIK_4] = SDLK_4; | |
790 DIK_keymap[DIK_5] = SDLK_5; | |
791 DIK_keymap[DIK_6] = SDLK_6; | |
792 DIK_keymap[DIK_7] = SDLK_7; | |
793 DIK_keymap[DIK_8] = SDLK_8; | |
794 DIK_keymap[DIK_9] = SDLK_9; | |
795 DIK_keymap[DIK_0] = SDLK_0; | |
796 DIK_keymap[DIK_MINUS] = SDLK_MINUS; | |
797 DIK_keymap[DIK_EQUALS] = SDLK_EQUALS; | |
798 DIK_keymap[DIK_BACK] = SDLK_BACKSPACE; | |
799 DIK_keymap[DIK_TAB] = SDLK_TAB; | |
800 DIK_keymap[DIK_Q] = SDLK_q; | |
801 DIK_keymap[DIK_W] = SDLK_w; | |
802 DIK_keymap[DIK_E] = SDLK_e; | |
803 DIK_keymap[DIK_R] = SDLK_r; | |
804 DIK_keymap[DIK_T] = SDLK_t; | |
805 DIK_keymap[DIK_Y] = SDLK_y; | |
806 DIK_keymap[DIK_U] = SDLK_u; | |
807 DIK_keymap[DIK_I] = SDLK_i; | |
808 DIK_keymap[DIK_O] = SDLK_o; | |
809 DIK_keymap[DIK_P] = SDLK_p; | |
810 DIK_keymap[DIK_LBRACKET] = SDLK_LEFTBRACKET; | |
811 DIK_keymap[DIK_RBRACKET] = SDLK_RIGHTBRACKET; | |
812 DIK_keymap[DIK_RETURN] = SDLK_RETURN; | |
813 DIK_keymap[DIK_LCONTROL] = SDLK_LCTRL; | |
814 DIK_keymap[DIK_A] = SDLK_a; | |
815 DIK_keymap[DIK_S] = SDLK_s; | |
816 DIK_keymap[DIK_D] = SDLK_d; | |
817 DIK_keymap[DIK_F] = SDLK_f; | |
818 DIK_keymap[DIK_G] = SDLK_g; | |
819 DIK_keymap[DIK_H] = SDLK_h; | |
820 DIK_keymap[DIK_J] = SDLK_j; | |
821 DIK_keymap[DIK_K] = SDLK_k; | |
822 DIK_keymap[DIK_L] = SDLK_l; | |
823 DIK_keymap[DIK_SEMICOLON] = SDLK_SEMICOLON; | |
824 DIK_keymap[DIK_APOSTROPHE] = SDLK_QUOTE; | |
825 DIK_keymap[DIK_GRAVE] = SDLK_BACKQUOTE; | |
826 DIK_keymap[DIK_LSHIFT] = SDLK_LSHIFT; | |
827 DIK_keymap[DIK_BACKSLASH] = SDLK_BACKSLASH; | |
1852
eb2d5480ae95
Try to keep SDL keysyms sane regardless of keyboard layout in windib target.
Ryan C. Gordon <icculus@icculus.org>
parents:
1526
diff
changeset
|
828 DIK_keymap[DIK_OEM_102] = SDLK_LESS; |
0 | 829 DIK_keymap[DIK_Z] = SDLK_z; |
830 DIK_keymap[DIK_X] = SDLK_x; | |
831 DIK_keymap[DIK_C] = SDLK_c; | |
832 DIK_keymap[DIK_V] = SDLK_v; | |
833 DIK_keymap[DIK_B] = SDLK_b; | |
834 DIK_keymap[DIK_N] = SDLK_n; | |
835 DIK_keymap[DIK_M] = SDLK_m; | |
836 DIK_keymap[DIK_COMMA] = SDLK_COMMA; | |
837 DIK_keymap[DIK_PERIOD] = SDLK_PERIOD; | |
838 DIK_keymap[DIK_SLASH] = SDLK_SLASH; | |
839 DIK_keymap[DIK_RSHIFT] = SDLK_RSHIFT; | |
840 DIK_keymap[DIK_MULTIPLY] = SDLK_KP_MULTIPLY; | |
841 DIK_keymap[DIK_LMENU] = SDLK_LALT; | |
842 DIK_keymap[DIK_SPACE] = SDLK_SPACE; | |
843 DIK_keymap[DIK_CAPITAL] = SDLK_CAPSLOCK; | |
844 DIK_keymap[DIK_F1] = SDLK_F1; | |
845 DIK_keymap[DIK_F2] = SDLK_F2; | |
846 DIK_keymap[DIK_F3] = SDLK_F3; | |
847 DIK_keymap[DIK_F4] = SDLK_F4; | |
848 DIK_keymap[DIK_F5] = SDLK_F5; | |
849 DIK_keymap[DIK_F6] = SDLK_F6; | |
850 DIK_keymap[DIK_F7] = SDLK_F7; | |
851 DIK_keymap[DIK_F8] = SDLK_F8; | |
852 DIK_keymap[DIK_F9] = SDLK_F9; | |
853 DIK_keymap[DIK_F10] = SDLK_F10; | |
854 DIK_keymap[DIK_NUMLOCK] = SDLK_NUMLOCK; | |
855 DIK_keymap[DIK_SCROLL] = SDLK_SCROLLOCK; | |
856 DIK_keymap[DIK_NUMPAD7] = SDLK_KP7; | |
857 DIK_keymap[DIK_NUMPAD8] = SDLK_KP8; | |
858 DIK_keymap[DIK_NUMPAD9] = SDLK_KP9; | |
859 DIK_keymap[DIK_SUBTRACT] = SDLK_KP_MINUS; | |
860 DIK_keymap[DIK_NUMPAD4] = SDLK_KP4; | |
861 DIK_keymap[DIK_NUMPAD5] = SDLK_KP5; | |
862 DIK_keymap[DIK_NUMPAD6] = SDLK_KP6; | |
863 DIK_keymap[DIK_ADD] = SDLK_KP_PLUS; | |
864 DIK_keymap[DIK_NUMPAD1] = SDLK_KP1; | |
865 DIK_keymap[DIK_NUMPAD2] = SDLK_KP2; | |
866 DIK_keymap[DIK_NUMPAD3] = SDLK_KP3; | |
867 DIK_keymap[DIK_NUMPAD0] = SDLK_KP0; | |
868 DIK_keymap[DIK_DECIMAL] = SDLK_KP_PERIOD; | |
869 DIK_keymap[DIK_F11] = SDLK_F11; | |
870 DIK_keymap[DIK_F12] = SDLK_F12; | |
871 | |
872 DIK_keymap[DIK_F13] = SDLK_F13; | |
873 DIK_keymap[DIK_F14] = SDLK_F14; | |
874 DIK_keymap[DIK_F15] = SDLK_F15; | |
875 | |
876 DIK_keymap[DIK_NUMPADEQUALS] = SDLK_KP_EQUALS; | |
877 DIK_keymap[DIK_NUMPADENTER] = SDLK_KP_ENTER; | |
878 DIK_keymap[DIK_RCONTROL] = SDLK_RCTRL; | |
879 DIK_keymap[DIK_DIVIDE] = SDLK_KP_DIVIDE; | |
1526 | 880 DIK_keymap[DIK_SYSRQ] = SDLK_PRINT; |
0 | 881 DIK_keymap[DIK_RMENU] = SDLK_RALT; |
290
9a02597bc1b0
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
275
diff
changeset
|
882 DIK_keymap[DIK_PAUSE] = SDLK_PAUSE; |
0 | 883 DIK_keymap[DIK_HOME] = SDLK_HOME; |
884 DIK_keymap[DIK_UP] = SDLK_UP; | |
885 DIK_keymap[DIK_PRIOR] = SDLK_PAGEUP; | |
886 DIK_keymap[DIK_LEFT] = SDLK_LEFT; | |
887 DIK_keymap[DIK_RIGHT] = SDLK_RIGHT; | |
888 DIK_keymap[DIK_END] = SDLK_END; | |
889 DIK_keymap[DIK_DOWN] = SDLK_DOWN; | |
890 DIK_keymap[DIK_NEXT] = SDLK_PAGEDOWN; | |
891 DIK_keymap[DIK_INSERT] = SDLK_INSERT; | |
892 DIK_keymap[DIK_DELETE] = SDLK_DELETE; | |
893 DIK_keymap[DIK_LWIN] = SDLK_LMETA; | |
894 DIK_keymap[DIK_RWIN] = SDLK_RMETA; | |
895 DIK_keymap[DIK_APPS] = SDLK_MENU; | |
896 } | |
897 | |
898 static SDL_keysym *TranslateKey(UINT scancode, SDL_keysym *keysym, int pressed) | |
899 { | |
900 /* Set the keysym information */ | |
901 keysym->scancode = (unsigned char)scancode; | |
902 keysym->sym = DIK_keymap[scancode]; | |
903 keysym->mod = KMOD_NONE; | |
904 keysym->unicode = 0; | |
1253
7c7ddaf195bf
Implemented ToUnicode() support on Windows 95/98/ME/NT/2000/XP
Sam Lantinga <slouken@libsdl.org>
parents:
1115
diff
changeset
|
905 if ( pressed && SDL_TranslateUNICODE ) { |
0 | 906 UINT vkey; |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
907 #ifndef NO_GETKEYBOARDSTATE |
1253
7c7ddaf195bf
Implemented ToUnicode() support on Windows 95/98/ME/NT/2000/XP
Sam Lantinga <slouken@libsdl.org>
parents:
1115
diff
changeset
|
908 BYTE keystate[256]; |
7c7ddaf195bf
Implemented ToUnicode() support on Windows 95/98/ME/NT/2000/XP
Sam Lantinga <slouken@libsdl.org>
parents:
1115
diff
changeset
|
909 Uint16 wchars[2]; |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
910 #endif |
0 | 911 |
912 vkey = MapVirtualKey(scancode, 1); | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
913 #ifdef NO_GETKEYBOARDSTATE |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
914 /* Uh oh, better hope the vkey is close enough.. */ |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
915 keysym->unicode = vkey; |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
916 #else |
0 | 917 GetKeyboardState(keystate); |
4170 | 918 /* Numlock isn't taken into account in ToUnicode, |
919 * so we handle it as a special case here */ | |
920 if ((keystate[VK_NUMLOCK] & 1) && vkey >= VK_NUMPAD0 && vkey <= VK_NUMPAD9) | |
921 { | |
922 keysym->unicode = vkey - VK_NUMPAD0 + '0'; | |
923 } | |
924 else if (SDL_ToUnicode(vkey, scancode, keystate, wchars, sizeof(wchars)/sizeof(wchars[0]), 0) > 0) | |
1253
7c7ddaf195bf
Implemented ToUnicode() support on Windows 95/98/ME/NT/2000/XP
Sam Lantinga <slouken@libsdl.org>
parents:
1115
diff
changeset
|
925 { |
7c7ddaf195bf
Implemented ToUnicode() support on Windows 95/98/ME/NT/2000/XP
Sam Lantinga <slouken@libsdl.org>
parents:
1115
diff
changeset
|
926 keysym->unicode = wchars[0]; |
0 | 927 } |
1253
7c7ddaf195bf
Implemented ToUnicode() support on Windows 95/98/ME/NT/2000/XP
Sam Lantinga <slouken@libsdl.org>
parents:
1115
diff
changeset
|
928 #endif /* NO_GETKEYBOARDSTATE */ |
0 | 929 } |
930 return(keysym); | |
931 } | |
932 | |
933 int DX5_CreateWindow(_THIS) | |
934 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
935 char *windowid = SDL_getenv("SDL_WINDOWID"); |
0 | 936 int i; |
937 | |
938 /* Clear out DirectInput variables in case we fail */ | |
939 for ( i=0; i<MAX_INPUTS; ++i ) { | |
940 SDL_DIdev[i] = NULL; | |
941 SDL_DIevt[i] = NULL; | |
942 SDL_DIfun[i] = NULL; | |
943 } | |
944 | |
1288
ea3888b472bf
Cleaned up the app registration stuff a bit
Sam Lantinga <slouken@libsdl.org>
parents:
1280
diff
changeset
|
945 SDL_RegisterApp(NULL, 0, 0); |
1280
f61f045343d3
Re-query the SDL_WINDOWID each time we initialize the video
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
946 |
f61f045343d3
Re-query the SDL_WINDOWID each time we initialize the video
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
947 SDL_windowid = (windowid != NULL); |
0 | 948 if ( SDL_windowid ) { |
1456
84de7511f79f
Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
949 SDL_Window = (HWND)SDL_strtoull(windowid, NULL, 0); |
975
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
950 if ( SDL_Window == NULL ) { |
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
951 SDL_SetError("Couldn't get user specified window"); |
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
952 return(-1); |
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
953 } |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
954 |
458
a8a0a4f19df7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
453
diff
changeset
|
955 /* DJM: we want all event's for the user specified |
975
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
956 window to be handled by SDL. |
458
a8a0a4f19df7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
453
diff
changeset
|
957 */ |
1472
4aac8563c296
Fixed more Win64 portability issues
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
958 userWindowProc = (WNDPROCTYPE)GetWindowLongPtr(SDL_Window, GWLP_WNDPROC); |
4aac8563c296
Fixed more Win64 portability issues
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
959 SetWindowLongPtr(SDL_Window, GWLP_WNDPROC, (LONG_PTR)WinMessage); |
0 | 960 } else { |
961 SDL_Window = CreateWindow(SDL_Appname, SDL_Appname, | |
962 (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX), | |
833
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
963 CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, SDL_Instance, NULL); |
0 | 964 if ( SDL_Window == NULL ) { |
965 SDL_SetError("Couldn't create window"); | |
966 return(-1); | |
967 } | |
968 ShowWindow(SDL_Window, SW_HIDE); | |
969 } | |
970 | |
971 /* Initialize DirectInput */ | |
972 if ( DX5_DInputInit(this) < 0 ) { | |
973 return(-1); | |
974 } | |
975 | |
1523 | 976 /* JC 14 Mar 2006 |
977 Flush the message loop or this can cause big problems later | |
978 Especially if the user decides to use dialog boxes or assert()! | |
979 */ | |
980 WIN_FlushMessageQueue(); | |
981 | |
0 | 982 /* Ready to roll */ |
983 return(0); | |
984 } | |
985 | |
986 void DX5_DestroyWindow(_THIS) | |
987 { | |
988 /* Close down DirectInput */ | |
989 DX5_DInputQuit(this); | |
990 | |
991 /* Destroy our window */ | |
975
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
992 if ( SDL_windowid ) { |
1472
4aac8563c296
Fixed more Win64 portability issues
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
993 SetWindowLongPtr(SDL_Window, GWLP_WNDPROC, (LONG_PTR)userWindowProc); |
975
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
994 } else { |
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
995 DestroyWindow(SDL_Window); |
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
996 } |
1288
ea3888b472bf
Cleaned up the app registration stuff a bit
Sam Lantinga <slouken@libsdl.org>
parents:
1280
diff
changeset
|
997 SDL_UnregisterApp(); |
1523 | 998 |
999 /* JC 14 Mar 2006 | |
1000 Flush the message loop or this can cause big problems later | |
1001 Especially if the user decides to use dialog boxes or assert()! | |
1002 */ | |
1003 WIN_FlushMessageQueue(); | |
0 | 1004 } |