annotate src/video/windx5/SDL_dx5events.c @ 4391:07b330419439 SDL-1.2

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