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