Mercurial > sdl-ios-xcode
annotate src/video/windx5/SDL_dx5events.c @ 1102:f0919504adfd
Revert back change between 1.29 and 1.30
author | Patrice Mandin <patmandin@gmail.com> |
---|---|
date | Wed, 27 Jul 2005 16:30:12 +0000 |
parents | add87cc1de0a |
children | 242a35a85852 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
721
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
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 | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
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 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* CAUTION!!!! If you modify this file, check ../windib/SDL_sysevents.c */ | |
29 | |
30 #include "directx.h" | |
31 | |
32 #include <stdio.h> | |
33 #include "SDL_events.h" | |
34 #include "SDL_video.h" | |
35 #include "SDL_error.h" | |
36 #include "SDL_syswm.h" | |
37 #include "SDL_sysevents.h" | |
38 #include "SDL_events_c.h" | |
39 #include "SDL_lowvideo.h" | |
40 #include "SDL_dx5video.h" | |
41 | |
42 #ifndef WM_APP | |
43 #define WM_APP 0x8000 | |
44 #endif | |
45 | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
46 #ifdef _WIN32_WCE |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
47 #define NO_GETKEYBOARDSTATE |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
48 #endif |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
49 |
0 | 50 /* The keyboard and mouse device input */ |
51 #define MAX_INPUTS 16 /* Maximum of 16-1 input devices */ | |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
52 #define INPUT_QSIZE 512 /* Buffer up to 512 input messages */ |
0 | 53 |
54 static LPDIRECTINPUT dinput = NULL; | |
55 static LPDIRECTINPUTDEVICE2 SDL_DIdev[MAX_INPUTS]; | |
56 static HANDLE SDL_DIevt[MAX_INPUTS]; | |
57 static void (*SDL_DIfun[MAX_INPUTS])(const int, DIDEVICEOBJECTDATA *); | |
58 static int SDL_DIndev = 0; | |
59 static int mouse_lost; | |
60 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
|
61 static int mouse_buttons_swapped = 0; |
0 | 62 |
63 /* The translation table from a DirectInput scancode to an SDL keysym */ | |
64 static SDLKey DIK_keymap[256]; | |
65 static SDL_keysym *TranslateKey(UINT scancode, SDL_keysym *keysym, int pressed); | |
66 | |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
67 /* 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
|
68 and give him a chance to handle some messages. */ |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
69 static WNDPROC userWindowProc = NULL; |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
70 |
0 | 71 /* Convert a DirectInput return code to a text message */ |
72 static void SetDIerror(char *function, int code) | |
73 { | |
74 static char *error; | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
75 static char errbuf[1024]; |
0 | 76 |
77 errbuf[0] = 0; | |
78 switch (code) { | |
79 case DIERR_GENERIC: | |
80 error = "Undefined error!"; | |
81 break; | |
82 case DIERR_OLDDIRECTINPUTVERSION: | |
83 error = "Your version of DirectInput needs upgrading"; | |
84 break; | |
85 case DIERR_INVALIDPARAM: | |
86 error = "Invalid parameters"; | |
87 break; | |
88 case DIERR_OUTOFMEMORY: | |
89 error = "Out of memory"; | |
90 break; | |
91 case DIERR_DEVICENOTREG: | |
92 error = "Device not registered"; | |
93 break; | |
94 case DIERR_NOINTERFACE: | |
95 error = "Interface not supported"; | |
96 break; | |
97 case DIERR_NOTINITIALIZED: | |
98 error = "Device not initialized"; | |
99 break; | |
100 default: | |
101 sprintf(errbuf, "%s: Unknown DirectInput error: 0x%x", | |
102 function, code); | |
103 break; | |
104 } | |
105 if ( ! errbuf[0] ) { | |
106 sprintf(errbuf, "%s: %s", function, error); | |
107 } | |
108 SDL_SetError("%s", errbuf); | |
109 return; | |
110 } | |
111 | |
112 /* Initialize DirectInput | |
113 Note: If NONEXCLUSIVE access is requested for the devices, normal | |
114 windows input messages will continue to be generated for that | |
115 input device, in addition to DirectInput messages. | |
116 */ | |
117 static void handle_keyboard(const int numevents, DIDEVICEOBJECTDATA *events); | |
118 static void handle_mouse(const int numevents, DIDEVICEOBJECTDATA *events); | |
119 struct { | |
120 char *name; | |
121 REFGUID guid; | |
122 LPCDIDATAFORMAT format; | |
123 DWORD win_level; | |
124 DWORD raw_level; | |
125 void (*fun)(const int numevents, DIDEVICEOBJECTDATA *events); | |
126 } inputs[] = { | |
127 { "keyboard", | |
128 &GUID_SysKeyboard, &c_dfDIKeyboard, | |
129 (DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), | |
130 (DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), handle_keyboard }, | |
131 { "mouse", | |
132 &GUID_SysMouse, &c_dfDIMouse, | |
133 (DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), | |
134 (DISCL_FOREGROUND|DISCL_EXCLUSIVE), handle_mouse }, | |
135 { NULL, NULL, NULL, 0, 0, NULL } | |
136 }; | |
137 | |
138 static int DX5_DInputInit(_THIS) | |
139 { | |
140 int i; | |
141 LPDIRECTINPUTDEVICE device; | |
142 HRESULT result; | |
143 DIPROPDWORD dipdw; | |
970
fb8b91365766
Date: Tue, 19 Oct 2004 23:04:58 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
833
diff
changeset
|
144 HWND topwnd; |
0 | 145 |
146 /* Create the DirectInput object */ | |
147 result = DInputCreate(SDL_Instance, DIRECTINPUT_VERSION, | |
148 &dinput, NULL); | |
149 if ( result != DI_OK ) { | |
150 SetDIerror("DirectInputCreate", result); | |
151 return(-1); | |
152 } | |
153 | |
154 /* Create all of our registered input devices */ | |
155 SDL_DIndev = 0; | |
156 for ( i=0; inputs[i].name; ++i ) { | |
157 /* Create the DirectInput device */ | |
158 result = IDirectInput_CreateDevice(dinput, inputs[i].guid, | |
159 &device, NULL); | |
160 if ( result != DI_OK ) { | |
161 SetDIerror("DirectInput::CreateDevice", result); | |
162 return(-1); | |
163 } | |
164 result = IDirectInputDevice_QueryInterface(device, | |
165 &IID_IDirectInputDevice2, (LPVOID *)&SDL_DIdev[i]); | |
166 IDirectInputDevice_Release(device); | |
167 if ( result != DI_OK ) { | |
168 SetDIerror("DirectInputDevice::QueryInterface", result); | |
169 return(-1); | |
170 } | |
970
fb8b91365766
Date: Tue, 19 Oct 2004 23:04:58 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
833
diff
changeset
|
171 topwnd = GetAncestor(SDL_Window, GA_ROOT); |
0 | 172 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
|
173 topwnd, inputs[i].win_level); |
0 | 174 if ( result != DI_OK ) { |
175 SetDIerror("DirectInputDevice::SetCooperativeLevel", | |
176 result); | |
177 return(-1); | |
178 } | |
179 result = IDirectInputDevice2_SetDataFormat(SDL_DIdev[i], | |
180 inputs[i].format); | |
181 if ( result != DI_OK ) { | |
182 SetDIerror("DirectInputDevice::SetDataFormat", result); | |
183 return(-1); | |
184 } | |
185 | |
186 /* Set buffered input -- we aren't polling */ | |
187 memset(&dipdw, 0, sizeof(dipdw)); | |
188 dipdw.diph.dwSize = sizeof(dipdw); | |
189 dipdw.diph.dwHeaderSize = sizeof(dipdw.diph); | |
190 dipdw.diph.dwObj = 0; | |
191 dipdw.diph.dwHow = DIPH_DEVICE; | |
192 dipdw.dwData = INPUT_QSIZE; | |
193 result = IDirectInputDevice2_SetProperty(SDL_DIdev[i], | |
194 DIPROP_BUFFERSIZE, &dipdw.diph); | |
195 if ( result != DI_OK ) { | |
196 SetDIerror("DirectInputDevice::SetProperty", result); | |
197 return(-1); | |
198 } | |
199 | |
200 /* Create an event to be signaled when input is ready */ | |
201 SDL_DIevt[i] = CreateEvent(NULL, FALSE, FALSE, NULL); | |
202 if ( SDL_DIevt[i] == NULL ) { | |
203 SDL_SetError("Couldn't create DirectInput event"); | |
204 return(-1); | |
205 } | |
206 result = IDirectInputDevice2_SetEventNotification(SDL_DIdev[i], | |
207 SDL_DIevt[i]); | |
208 if ( result != DI_OK ) { | |
209 SetDIerror("DirectInputDevice::SetEventNotification", | |
210 result); | |
211 return(-1); | |
212 } | |
213 SDL_DIfun[i] = inputs[i].fun; | |
214 | |
215 /* Acquire the device for input */ | |
216 IDirectInputDevice2_Acquire(SDL_DIdev[i]); | |
217 | |
218 /* Increment the number of devices we have */ | |
219 ++SDL_DIndev; | |
220 } | |
221 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
|
222 mouse_buttons_swapped = GetSystemMetrics(SM_SWAPBUTTON); |
0 | 223 |
224 /* DirectInput is ready! */ | |
225 return(0); | |
226 } | |
227 | |
228 /* Clean up DirectInput */ | |
229 static void DX5_DInputQuit(_THIS) | |
230 { | |
231 int i; | |
232 | |
233 if ( dinput != NULL ) { | |
234 /* Close and release all DirectInput devices */ | |
235 for ( i=0; i<MAX_INPUTS; ++i ) { | |
236 if ( SDL_DIdev[i] != NULL ) { | |
237 IDirectInputDevice2_Unacquire(SDL_DIdev[i]); | |
238 IDirectInputDevice2_SetEventNotification( | |
239 SDL_DIdev[i], NULL); | |
240 if ( SDL_DIevt[i] != NULL ) { | |
241 CloseHandle(SDL_DIevt[i]); | |
242 SDL_DIevt[i] = NULL; | |
243 } | |
244 IDirectInputDevice2_Release(SDL_DIdev[i]); | |
245 SDL_DIdev[i] = NULL; | |
246 } | |
247 } | |
248 /* Release DirectInput */ | |
249 IDirectInput_Release(dinput); | |
250 dinput = NULL; | |
251 } | |
252 } | |
253 | |
254 /* Flag to tell SDL whether or not we queued an event */ | |
255 static int posted = 0; | |
256 | |
257 /* Input event handler functions */ | |
258 static void handle_keyboard(const int numevents, DIDEVICEOBJECTDATA *keybuf) | |
259 { | |
260 int i; | |
261 SDL_keysym keysym; | |
262 | |
263 /* Translate keyboard messages */ | |
264 for ( i=0; i<numevents; ++i ) { | |
265 if ( keybuf[i].dwData & 0x80 ) { | |
266 posted = SDL_PrivateKeyboard(SDL_PRESSED, | |
267 TranslateKey(keybuf[i].dwOfs, &keysym, 1)); | |
268 } else { | |
269 posted = SDL_PrivateKeyboard(SDL_RELEASED, | |
270 TranslateKey(keybuf[i].dwOfs, &keysym, 0)); | |
271 } | |
272 } | |
273 } | |
274 static void handle_mouse(const int numevents, DIDEVICEOBJECTDATA *ptrbuf) | |
275 { | |
276 int i; | |
277 Sint16 xrel, yrel; | |
278 Uint8 state; | |
279 Uint8 button; | |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
280 DWORD timestamp = 0; |
0 | 281 |
717
42ed44b2c8b6
Date: Sun, 14 Sep 2003 17:04:55 -0400
Ryan C. Gordon <icculus@icculus.org>
parents:
536
diff
changeset
|
282 /* 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
|
283 if (SDL_PublicSurface == NULL) { |
42ed44b2c8b6
Date: Sun, 14 Sep 2003 17:04:55 -0400
Ryan C. Gordon <icculus@icculus.org>
parents:
536
diff
changeset
|
284 return; |
42ed44b2c8b6
Date: Sun, 14 Sep 2003 17:04:55 -0400
Ryan C. Gordon <icculus@icculus.org>
parents:
536
diff
changeset
|
285 } |
42ed44b2c8b6
Date: Sun, 14 Sep 2003 17:04:55 -0400
Ryan C. Gordon <icculus@icculus.org>
parents:
536
diff
changeset
|
286 |
0 | 287 /* If we are in windowed mode, Windows is taking care of the mouse */ |
325
1b5457c0a8ad
Fixed the bug where mouse cursor and SDL mouse coordinates didn't match
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
288 if ( (SDL_PublicSurface->flags & SDL_OPENGL) || |
1b5457c0a8ad
Fixed the bug where mouse cursor and SDL mouse coordinates didn't match
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
289 !(SDL_PublicSurface->flags & SDL_FULLSCREEN) ) { |
0 | 290 return; |
291 } | |
292 | |
293 /* If the mouse was lost, regain some sense of mouse state */ | |
294 if ( mouse_lost ) { | |
295 POINT mouse_pos; | |
296 Uint8 old_state; | |
297 Uint8 new_state; | |
298 | |
299 /* Set ourselves up with the current cursor position */ | |
300 GetCursorPos(&mouse_pos); | |
301 ScreenToClient(SDL_Window, &mouse_pos); | |
302 posted = SDL_PrivateMouseMotion(0, 0, | |
303 (Sint16)mouse_pos.x, (Sint16)mouse_pos.y); | |
304 | |
305 /* Check for mouse button changes */ | |
306 old_state = SDL_GetMouseState(NULL, NULL); | |
307 new_state = 0; | |
308 { /* Get the new DirectInput button state for the mouse */ | |
309 DIMOUSESTATE distate; | |
310 HRESULT result; | |
311 | |
312 result=IDirectInputDevice2_GetDeviceState(SDL_DIdev[1], | |
313 sizeof(distate), &distate); | |
314 if ( result != DI_OK ) { | |
315 /* Try again next time */ | |
316 SetDIerror( | |
317 "IDirectInputDevice2::GetDeviceState", result); | |
318 return; | |
319 } | |
320 for ( i=3; i>=0; --i ) { | |
321 if ( (distate.rgbButtons[i]&0x80) == 0x80 ) { | |
322 new_state |= 0x01; | |
323 } | |
324 new_state <<= 1; | |
325 } | |
326 } | |
327 for ( i=0; i<8; ++i ) { | |
328 if ( (old_state&0x01) != (new_state&0x01) ) { | |
329 button = (Uint8)(i+1); | |
330 /* Button #2 on two button mice is button 3 | |
331 (the middle button is button 2) | |
332 */ | |
333 if ( button == 2 ) { | |
334 button = 3; | |
335 } else | |
336 if ( button == 3 ) { | |
337 button = 2; | |
338 } | |
339 if ( new_state & 0x01 ) { | |
340 /* Grab mouse so we get mouse-up */ | |
341 if ( ++mouse_pressed > 0 ) { | |
342 SetCapture(SDL_Window); | |
343 } | |
344 state = SDL_PRESSED; | |
345 } else { | |
346 /* Release mouse after all mouse-ups */ | |
347 if ( --mouse_pressed <= 0 ) { | |
348 ReleaseCapture(); | |
349 mouse_pressed = 0; | |
350 } | |
351 state = SDL_RELEASED; | |
352 } | |
491
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
353 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
|
354 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
|
355 else |
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
356 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
|
357 } |
0 | 358 posted = SDL_PrivateMouseButton(state, button, |
359 0, 0); | |
360 } | |
361 old_state >>= 1; | |
362 new_state >>= 1; | |
363 } | |
364 mouse_lost = 0; | |
365 return; | |
366 } | |
367 | |
368 /* Translate mouse messages */ | |
369 xrel = 0; | |
370 yrel = 0; | |
371 for ( i=0; i<(int)numevents; ++i ) { | |
372 switch (ptrbuf[i].dwOfs) { | |
373 case DIMOFS_X: | |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
374 if ( timestamp != ptrbuf[i].dwTimeStamp ) { |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
375 if ( xrel || yrel ) { |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
376 posted = SDL_PrivateMouseMotion( |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
377 0, 1, xrel, yrel); |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
378 xrel = 0; |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
379 yrel = 0; |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
380 } |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
381 timestamp = ptrbuf[i].dwTimeStamp; |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
382 } |
0 | 383 xrel += (Sint16)ptrbuf[i].dwData; |
384 break; | |
385 case DIMOFS_Y: | |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
386 if ( timestamp != ptrbuf[i].dwTimeStamp ) { |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
387 if ( xrel || yrel ) { |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
388 posted = SDL_PrivateMouseMotion( |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
389 0, 1, xrel, yrel); |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
390 xrel = 0; |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
391 yrel = 0; |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
392 } |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
393 timestamp = ptrbuf[i].dwTimeStamp; |
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
394 } |
0 | 395 yrel += (Sint16)ptrbuf[i].dwData; |
396 break; | |
61
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
397 case DIMOFS_Z: |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
398 if ( xrel || yrel ) { |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
399 posted = SDL_PrivateMouseMotion( |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
400 0, 1, xrel, yrel); |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
401 xrel = 0; |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
402 yrel = 0; |
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
403 } |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
404 timestamp = 0; |
61
994ed1d668e7
Mouse wheel sends mouse button (4/5) events on Windows
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
405 if((int)ptrbuf[i].dwData > 0) |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
406 button = SDL_BUTTON_WHEELUP; |
332 | 407 else |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
408 button = SDL_BUTTON_WHEELDOWN; |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
409 posted = SDL_PrivateMouseButton( |
332 | 410 SDL_PRESSED, button, 0, 0); |
411 posted |= SDL_PrivateMouseButton( | |
412 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
|
413 break; |
0 | 414 case DIMOFS_BUTTON0: |
415 case DIMOFS_BUTTON1: | |
416 case DIMOFS_BUTTON2: | |
417 case DIMOFS_BUTTON3: | |
418 if ( xrel || yrel ) { | |
419 posted = SDL_PrivateMouseMotion( | |
420 0, 1, xrel, yrel); | |
421 xrel = 0; | |
422 yrel = 0; | |
423 } | |
536
bf7f477fb2b2
Fixed potential dropped events under DirectInput
Sam Lantinga <slouken@libsdl.org>
parents:
523
diff
changeset
|
424 timestamp = 0; |
0 | 425 button = (Uint8)(ptrbuf[i].dwOfs-DIMOFS_BUTTON0)+1; |
426 /* Button #2 on two button mice is button 3 | |
427 (the middle button is button 2) | |
428 */ | |
429 if ( button == 2 ) { | |
430 button = 3; | |
431 } else | |
432 if ( button == 3 ) { | |
433 button = 2; | |
434 } | |
435 if ( ptrbuf[i].dwData & 0x80 ) { | |
436 /* Grab mouse so we get mouse-up */ | |
437 if ( ++mouse_pressed > 0 ) { | |
438 SetCapture(SDL_Window); | |
439 } | |
440 state = SDL_PRESSED; | |
441 } else { | |
442 /* Release mouse after all mouse-ups */ | |
443 if ( --mouse_pressed <= 0 ) { | |
444 ReleaseCapture(); | |
445 mouse_pressed = 0; | |
446 } | |
447 state = SDL_RELEASED; | |
448 } | |
491
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
449 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
|
450 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
|
451 else |
da6a7e859616
Applied John Popplewell's fix for left-handed mice under Windows.
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
452 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
|
453 } |
0 | 454 posted = SDL_PrivateMouseButton(state, button, |
455 0, 0); | |
456 break; | |
457 } | |
458 } | |
459 if ( xrel || yrel ) { | |
460 posted = SDL_PrivateMouseMotion( 0, 1, xrel, yrel); | |
461 } | |
462 } | |
463 | |
464 /* The main Win32 event handler */ | |
465 LONG | |
466 DX5_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | |
467 { | |
468 switch (msg) { | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
469 #ifdef WM_ACTIVATEAPP |
0 | 470 case WM_ACTIVATEAPP: { |
471 int i, active; | |
472 | |
473 active = (wParam && (GetForegroundWindow() == hwnd)); | |
474 if ( active ) { | |
475 for ( i=0; SDL_DIdev[i]; ++i ) { | |
476 IDirectInputDevice2_Acquire( | |
477 SDL_DIdev[i]); | |
478 } | |
479 } else { | |
480 for ( i=0; SDL_DIdev[i]; ++i ) { | |
481 IDirectInputDevice2_Unacquire( | |
482 SDL_DIdev[i]); | |
483 } | |
484 mouse_lost = 1; | |
485 } | |
486 } | |
487 break; | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
488 #endif /* WM_ACTIVATEAPP */ |
0 | 489 |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
490 #ifdef WM_DISPLAYCHANGE |
0 | 491 case WM_DISPLAYCHANGE: { |
492 WORD BitsPerPixel; | |
493 WORD SizeX, SizeY; | |
494 | |
495 /* Ack! The display changed size and/or depth! */ | |
496 SizeX = LOWORD(lParam); | |
497 SizeY = HIWORD(lParam); | |
498 BitsPerPixel = wParam; | |
499 /* We cause this message when we go fullscreen */ | |
500 } | |
501 break; | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
502 #endif /* WM_DISPLAYCHANGE */ |
0 | 503 |
504 /* The keyboard is handled via DirectInput */ | |
505 case WM_SYSKEYUP: | |
506 case WM_SYSKEYDOWN: | |
507 case WM_KEYUP: | |
508 case WM_KEYDOWN: { | |
509 /* Ignore windows keyboard messages */; | |
510 } | |
511 return(0); | |
512 | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
513 #if defined(SC_SCREENSAVE) || defined(SC_MONITORPOWER) |
0 | 514 /* Don't allow screen savers or monitor power downs. |
515 This is because they quietly clear DirectX surfaces. | |
516 It would be better to allow the application to | |
517 decide whether or not to blow these off, but the | |
518 semantics of SDL_PrivateSysWMEvent() don't allow | |
519 the application that choice. | |
520 */ | |
521 case WM_SYSCOMMAND: { | |
522 if ((wParam&0xFFF0)==SC_SCREENSAVE || | |
523 (wParam&0xFFF0)==SC_MONITORPOWER) | |
524 return(0); | |
525 } | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
526 /* Fall through to default processing */ |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
527 |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
528 #endif /* SC_SCREENSAVE || SC_MONITORPOWER */ |
0 | 529 |
530 default: { | |
531 /* Only post the event if we're watching for it */ | |
532 if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { | |
533 SDL_SysWMmsg wmmsg; | |
534 | |
535 SDL_VERSION(&wmmsg.version); | |
536 wmmsg.hwnd = hwnd; | |
537 wmmsg.msg = msg; | |
538 wmmsg.wParam = wParam; | |
539 wmmsg.lParam = lParam; | |
540 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
|
541 |
721
ab0656314eef
Date: Thu, 18 Sep 2003 14:24:35 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
717
diff
changeset
|
542 /* 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
|
543 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
|
544 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
|
545 */ |
ab0656314eef
Date: Thu, 18 Sep 2003 14:24:35 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
717
diff
changeset
|
546 } else if (userWindowProc) { |
ab0656314eef
Date: Thu, 18 Sep 2003 14:24:35 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
717
diff
changeset
|
547 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
|
548 } |
0 | 549 } |
550 break; | |
551 } | |
552 return(DefWindowProc(hwnd, msg, wParam, lParam)); | |
553 } | |
554 | |
555 /* This function checks the windows message queue and DirectInput and returns | |
556 1 if there was input, 0 if there was no input, or -1 if the application has | |
557 posted a quit message. | |
558 */ | |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
559 static int DX5_CheckInput(_THIS, int timeout, BOOL processInput) |
0 | 560 { |
561 MSG msg; | |
562 int i; | |
563 HRESULT result; | |
564 DWORD event; | |
565 | |
566 /* Check the normal windows queue (highest preference) */ | |
567 posted = 0; | |
568 while ( ! posted && | |
523
c210010f50f4
Fixed windows event handling for ActiveX controls (thanks Huib-Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
491
diff
changeset
|
569 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
|
570 if ( GetMessage(&msg, NULL, 0, 0) > 0 ) { |
0 | 571 DispatchMessage(&msg); |
572 } else { | |
573 return(-1); | |
574 } | |
575 } | |
576 if ( posted ) { | |
577 return(1); | |
578 } | |
579 | |
580 /* Pump the DirectInput flow */ | |
581 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
582 for ( i=0; i<SDL_DIndev; ++i ) { | |
583 result = IDirectInputDevice2_Poll(SDL_DIdev[i]); | |
584 if ( (result == DIERR_INPUTLOST) || | |
585 (result == DIERR_NOTACQUIRED) ) { | |
586 if ( strcmp(inputs[i].name, "mouse") == 0 ) { | |
587 mouse_lost = 1; | |
588 } | |
589 IDirectInputDevice2_Acquire(SDL_DIdev[i]); | |
590 IDirectInputDevice2_Poll(SDL_DIdev[i]); | |
591 } | |
592 } | |
593 } | |
594 | |
595 /* Wait for messages and input events */ | |
596 event = MsgWaitForMultipleObjects(SDL_DIndev, SDL_DIevt, FALSE, | |
597 timeout, QS_ALLEVENTS); | |
598 if ((event >= WAIT_OBJECT_0) && (event < (WAIT_OBJECT_0+SDL_DIndev))) { | |
599 DWORD numevents; | |
600 DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE]; | |
601 | |
602 event -= WAIT_OBJECT_0; | |
603 numevents = INPUT_QSIZE; | |
604 result = IDirectInputDevice2_GetDeviceData( | |
605 SDL_DIdev[event], sizeof(DIDEVICEOBJECTDATA), | |
606 evtbuf, &numevents, 0); | |
607 if ( (result == DIERR_INPUTLOST) || | |
608 (result == DIERR_NOTACQUIRED) ) { | |
609 if ( strcmp(inputs[event].name, "mouse") == 0 ) { | |
610 mouse_lost = 1; | |
611 } | |
612 IDirectInputDevice2_Acquire(SDL_DIdev[event]); | |
613 result = IDirectInputDevice2_GetDeviceData( | |
614 SDL_DIdev[event], sizeof(DIDEVICEOBJECTDATA), | |
615 evtbuf, &numevents, 0); | |
616 } | |
617 /* Handle the events */ | |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
618 if ( result == DI_OK && processInput ) { |
0 | 619 /* Note: This can post multiple events to event queue |
620 */ | |
621 (*SDL_DIfun[event])((int)numevents, evtbuf); | |
622 return(1); | |
623 } | |
624 } | |
625 if ( event != WAIT_TIMEOUT ) { | |
626 /* Maybe there was a windows message? */ | |
627 if ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { | |
628 if ( GetMessage(&msg, NULL, 0, 0) > 0 ) { | |
629 DispatchMessage(&msg); | |
630 } else { | |
631 return(-1); | |
632 } | |
633 return(1); | |
634 } | |
635 } | |
636 return(0); | |
637 } | |
638 | |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
639 /* 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
|
640 void DX5_DInputReset(_THIS, int fullscreen) |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
641 { |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
642 DWORD level; |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
643 int i; |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
644 HRESULT result; |
970
fb8b91365766
Date: Tue, 19 Oct 2004 23:04:58 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
833
diff
changeset
|
645 HWND topwnd; |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
646 |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
647 for ( i=0; i<MAX_INPUTS; ++i ) { |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
648 if ( SDL_DIdev[i] != NULL ) { |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
649 if ( fullscreen ) { |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
650 level = inputs[i].raw_level; |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
651 } else { |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
652 level = inputs[i].win_level; |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
653 } |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
654 IDirectInputDevice2_Unacquire(SDL_DIdev[i]); |
970
fb8b91365766
Date: Tue, 19 Oct 2004 23:04:58 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
833
diff
changeset
|
655 topwnd = GetAncestor(SDL_Window, GA_ROOT); |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
656 result = IDirectInputDevice2_SetCooperativeLevel( |
970
fb8b91365766
Date: Tue, 19 Oct 2004 23:04:58 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
833
diff
changeset
|
657 SDL_DIdev[i], topwnd, level); |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
658 IDirectInputDevice2_Acquire(SDL_DIdev[i]); |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
659 if ( result != DI_OK ) { |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
660 SetDIerror( |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
661 "DirectInputDevice::SetCooperativeLevel", result); |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
662 } |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
663 } |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
664 } |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
665 mouse_lost = 1; |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
666 |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
667 /* Flush pending input */ |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
668 DX5_CheckInput(this, 0, FALSE); |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
669 } |
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
670 |
0 | 671 void DX5_PumpEvents(_THIS) |
672 { | |
673 /* Wait for messages and DirectInput */ | |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
458
diff
changeset
|
674 while ( DX5_CheckInput(this, 0, TRUE) > 0 ) { |
0 | 675 /* Loop and check again */; |
676 } | |
677 } | |
678 | |
679 void DX5_InitOSKeymap(_THIS) | |
680 { | |
275
53fc686e9428
Added support for the pause key under DirectX
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
681 #ifndef DIK_PAUSE |
53fc686e9428
Added support for the pause key under DirectX
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
682 #define DIK_PAUSE 0xC5 |
53fc686e9428
Added support for the pause key under DirectX
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
683 #endif |
327
13fc64213765
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
325
diff
changeset
|
684 #ifndef DIK_OEM_102 |
13fc64213765
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
325
diff
changeset
|
685 #define DIK_OEM_102 0x56 /* < > | on UK/Germany keyboards */ |
13fc64213765
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
325
diff
changeset
|
686 #endif |
0 | 687 int i; |
688 | |
689 /* Map the DIK scancodes to SDL keysyms */ | |
690 for ( i=0; i<SDL_TABLESIZE(DIK_keymap); ++i ) | |
691 DIK_keymap[i] = 0; | |
692 | |
693 /* Defined DIK_* constants */ | |
694 DIK_keymap[DIK_ESCAPE] = SDLK_ESCAPE; | |
695 DIK_keymap[DIK_1] = SDLK_1; | |
696 DIK_keymap[DIK_2] = SDLK_2; | |
697 DIK_keymap[DIK_3] = SDLK_3; | |
698 DIK_keymap[DIK_4] = SDLK_4; | |
699 DIK_keymap[DIK_5] = SDLK_5; | |
700 DIK_keymap[DIK_6] = SDLK_6; | |
701 DIK_keymap[DIK_7] = SDLK_7; | |
702 DIK_keymap[DIK_8] = SDLK_8; | |
703 DIK_keymap[DIK_9] = SDLK_9; | |
704 DIK_keymap[DIK_0] = SDLK_0; | |
705 DIK_keymap[DIK_MINUS] = SDLK_MINUS; | |
706 DIK_keymap[DIK_EQUALS] = SDLK_EQUALS; | |
707 DIK_keymap[DIK_BACK] = SDLK_BACKSPACE; | |
708 DIK_keymap[DIK_TAB] = SDLK_TAB; | |
709 DIK_keymap[DIK_Q] = SDLK_q; | |
710 DIK_keymap[DIK_W] = SDLK_w; | |
711 DIK_keymap[DIK_E] = SDLK_e; | |
712 DIK_keymap[DIK_R] = SDLK_r; | |
713 DIK_keymap[DIK_T] = SDLK_t; | |
714 DIK_keymap[DIK_Y] = SDLK_y; | |
715 DIK_keymap[DIK_U] = SDLK_u; | |
716 DIK_keymap[DIK_I] = SDLK_i; | |
717 DIK_keymap[DIK_O] = SDLK_o; | |
718 DIK_keymap[DIK_P] = SDLK_p; | |
719 DIK_keymap[DIK_LBRACKET] = SDLK_LEFTBRACKET; | |
720 DIK_keymap[DIK_RBRACKET] = SDLK_RIGHTBRACKET; | |
721 DIK_keymap[DIK_RETURN] = SDLK_RETURN; | |
722 DIK_keymap[DIK_LCONTROL] = SDLK_LCTRL; | |
723 DIK_keymap[DIK_A] = SDLK_a; | |
724 DIK_keymap[DIK_S] = SDLK_s; | |
725 DIK_keymap[DIK_D] = SDLK_d; | |
726 DIK_keymap[DIK_F] = SDLK_f; | |
727 DIK_keymap[DIK_G] = SDLK_g; | |
728 DIK_keymap[DIK_H] = SDLK_h; | |
729 DIK_keymap[DIK_J] = SDLK_j; | |
730 DIK_keymap[DIK_K] = SDLK_k; | |
731 DIK_keymap[DIK_L] = SDLK_l; | |
732 DIK_keymap[DIK_SEMICOLON] = SDLK_SEMICOLON; | |
733 DIK_keymap[DIK_APOSTROPHE] = SDLK_QUOTE; | |
734 DIK_keymap[DIK_GRAVE] = SDLK_BACKQUOTE; | |
735 DIK_keymap[DIK_LSHIFT] = SDLK_LSHIFT; | |
736 DIK_keymap[DIK_BACKSLASH] = SDLK_BACKSLASH; | |
327
13fc64213765
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
325
diff
changeset
|
737 DIK_keymap[DIK_OEM_102] = SDLK_BACKSLASH; |
0 | 738 DIK_keymap[DIK_Z] = SDLK_z; |
739 DIK_keymap[DIK_X] = SDLK_x; | |
740 DIK_keymap[DIK_C] = SDLK_c; | |
741 DIK_keymap[DIK_V] = SDLK_v; | |
742 DIK_keymap[DIK_B] = SDLK_b; | |
743 DIK_keymap[DIK_N] = SDLK_n; | |
744 DIK_keymap[DIK_M] = SDLK_m; | |
745 DIK_keymap[DIK_COMMA] = SDLK_COMMA; | |
746 DIK_keymap[DIK_PERIOD] = SDLK_PERIOD; | |
747 DIK_keymap[DIK_SLASH] = SDLK_SLASH; | |
748 DIK_keymap[DIK_RSHIFT] = SDLK_RSHIFT; | |
749 DIK_keymap[DIK_MULTIPLY] = SDLK_KP_MULTIPLY; | |
750 DIK_keymap[DIK_LMENU] = SDLK_LALT; | |
751 DIK_keymap[DIK_SPACE] = SDLK_SPACE; | |
752 DIK_keymap[DIK_CAPITAL] = SDLK_CAPSLOCK; | |
753 DIK_keymap[DIK_F1] = SDLK_F1; | |
754 DIK_keymap[DIK_F2] = SDLK_F2; | |
755 DIK_keymap[DIK_F3] = SDLK_F3; | |
756 DIK_keymap[DIK_F4] = SDLK_F4; | |
757 DIK_keymap[DIK_F5] = SDLK_F5; | |
758 DIK_keymap[DIK_F6] = SDLK_F6; | |
759 DIK_keymap[DIK_F7] = SDLK_F7; | |
760 DIK_keymap[DIK_F8] = SDLK_F8; | |
761 DIK_keymap[DIK_F9] = SDLK_F9; | |
762 DIK_keymap[DIK_F10] = SDLK_F10; | |
763 DIK_keymap[DIK_NUMLOCK] = SDLK_NUMLOCK; | |
764 DIK_keymap[DIK_SCROLL] = SDLK_SCROLLOCK; | |
765 DIK_keymap[DIK_NUMPAD7] = SDLK_KP7; | |
766 DIK_keymap[DIK_NUMPAD8] = SDLK_KP8; | |
767 DIK_keymap[DIK_NUMPAD9] = SDLK_KP9; | |
768 DIK_keymap[DIK_SUBTRACT] = SDLK_KP_MINUS; | |
769 DIK_keymap[DIK_NUMPAD4] = SDLK_KP4; | |
770 DIK_keymap[DIK_NUMPAD5] = SDLK_KP5; | |
771 DIK_keymap[DIK_NUMPAD6] = SDLK_KP6; | |
772 DIK_keymap[DIK_ADD] = SDLK_KP_PLUS; | |
773 DIK_keymap[DIK_NUMPAD1] = SDLK_KP1; | |
774 DIK_keymap[DIK_NUMPAD2] = SDLK_KP2; | |
775 DIK_keymap[DIK_NUMPAD3] = SDLK_KP3; | |
776 DIK_keymap[DIK_NUMPAD0] = SDLK_KP0; | |
777 DIK_keymap[DIK_DECIMAL] = SDLK_KP_PERIOD; | |
778 DIK_keymap[DIK_F11] = SDLK_F11; | |
779 DIK_keymap[DIK_F12] = SDLK_F12; | |
780 | |
781 DIK_keymap[DIK_F13] = SDLK_F13; | |
782 DIK_keymap[DIK_F14] = SDLK_F14; | |
783 DIK_keymap[DIK_F15] = SDLK_F15; | |
784 | |
785 DIK_keymap[DIK_NUMPADEQUALS] = SDLK_KP_EQUALS; | |
786 DIK_keymap[DIK_NUMPADENTER] = SDLK_KP_ENTER; | |
787 DIK_keymap[DIK_RCONTROL] = SDLK_RCTRL; | |
788 DIK_keymap[DIK_DIVIDE] = SDLK_KP_DIVIDE; | |
789 DIK_keymap[DIK_SYSRQ] = SDLK_SYSREQ; | |
790 DIK_keymap[DIK_RMENU] = SDLK_RALT; | |
290
9a02597bc1b0
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
275
diff
changeset
|
791 DIK_keymap[DIK_PAUSE] = SDLK_PAUSE; |
0 | 792 DIK_keymap[DIK_HOME] = SDLK_HOME; |
793 DIK_keymap[DIK_UP] = SDLK_UP; | |
794 DIK_keymap[DIK_PRIOR] = SDLK_PAGEUP; | |
795 DIK_keymap[DIK_LEFT] = SDLK_LEFT; | |
796 DIK_keymap[DIK_RIGHT] = SDLK_RIGHT; | |
797 DIK_keymap[DIK_END] = SDLK_END; | |
798 DIK_keymap[DIK_DOWN] = SDLK_DOWN; | |
799 DIK_keymap[DIK_NEXT] = SDLK_PAGEDOWN; | |
800 DIK_keymap[DIK_INSERT] = SDLK_INSERT; | |
801 DIK_keymap[DIK_DELETE] = SDLK_DELETE; | |
802 DIK_keymap[DIK_LWIN] = SDLK_LMETA; | |
803 DIK_keymap[DIK_RWIN] = SDLK_RMETA; | |
804 DIK_keymap[DIK_APPS] = SDLK_MENU; | |
805 } | |
806 | |
807 static SDL_keysym *TranslateKey(UINT scancode, SDL_keysym *keysym, int pressed) | |
808 { | |
809 /* Set the keysym information */ | |
810 keysym->scancode = (unsigned char)scancode; | |
811 keysym->sym = DIK_keymap[scancode]; | |
812 keysym->mod = KMOD_NONE; | |
813 keysym->unicode = 0; | |
814 if ( pressed && SDL_TranslateUNICODE ) { /* Someday use ToUnicode() */ | |
815 UINT vkey; | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
816 #ifndef NO_GETKEYBOARDSTATE |
0 | 817 BYTE keystate[256]; |
818 BYTE chars[2]; | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
819 #endif |
0 | 820 |
821 vkey = MapVirtualKey(scancode, 1); | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
822 #ifdef NO_GETKEYBOARDSTATE |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
823 /* 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
|
824 keysym->unicode = vkey; |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
825 #else |
0 | 826 GetKeyboardState(keystate); |
827 if ( ToAscii(vkey,scancode,keystate,(WORD *)chars,0) == 1 ) { | |
828 keysym->unicode = chars[0]; | |
829 } | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
830 #endif |
0 | 831 } |
832 return(keysym); | |
833 } | |
834 | |
835 int DX5_CreateWindow(_THIS) | |
836 { | |
837 int i; | |
838 | |
839 /* Clear out DirectInput variables in case we fail */ | |
840 for ( i=0; i<MAX_INPUTS; ++i ) { | |
841 SDL_DIdev[i] = NULL; | |
842 SDL_DIevt[i] = NULL; | |
843 SDL_DIfun[i] = NULL; | |
844 } | |
845 | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
846 #ifndef CS_BYTEALIGNCLIENT |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
847 #define CS_BYTEALIGNCLIENT 0 |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
332
diff
changeset
|
848 #endif |
0 | 849 SDL_RegisterApp("SDL_app", CS_BYTEALIGNCLIENT, 0); |
850 if ( SDL_windowid ) { | |
851 SDL_Window = (HWND)strtol(SDL_windowid, NULL, 0); | |
975
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
852 if ( SDL_Window == NULL ) { |
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
853 SDL_SetError("Couldn't get user specified window"); |
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
854 return(-1); |
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
855 } |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
61
diff
changeset
|
856 |
458
a8a0a4f19df7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
453
diff
changeset
|
857 /* DJM: we want all event's for the user specified |
975
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
858 window to be handled by SDL. |
458
a8a0a4f19df7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
453
diff
changeset
|
859 */ |
975
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
860 userWindowProc = (WNDPROC)GetWindowLong(SDL_Window, GWL_WNDPROC); |
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
861 SetWindowLong(SDL_Window, GWL_WNDPROC, (LONG)WinMessage); |
0 | 862 } else { |
863 SDL_Window = CreateWindow(SDL_Appname, SDL_Appname, | |
864 (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
|
865 CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, SDL_Instance, NULL); |
0 | 866 if ( SDL_Window == NULL ) { |
867 SDL_SetError("Couldn't create window"); | |
868 return(-1); | |
869 } | |
870 ShowWindow(SDL_Window, SW_HIDE); | |
871 } | |
872 | |
873 /* Initialize DirectInput */ | |
874 if ( DX5_DInputInit(this) < 0 ) { | |
875 return(-1); | |
876 } | |
877 | |
878 /* Ready to roll */ | |
879 return(0); | |
880 } | |
881 | |
882 void DX5_DestroyWindow(_THIS) | |
883 { | |
884 /* Close down DirectInput */ | |
885 DX5_DInputQuit(this); | |
886 | |
887 /* Destroy our window */ | |
975
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
888 if ( SDL_windowid ) { |
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
889 SetWindowLong(SDL_Window, GWL_WNDPROC, (LONG)userWindowProc); |
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
890 } else { |
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
891 DestroyWindow(SDL_Window); |
add87cc1de0a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
970
diff
changeset
|
892 } |
0 | 893 } |