25 #define DIRECTINPUT_VERSION 0x0700
28 #ifndef DIDFT_OPTIONAL
29 #define DIDFT_OPTIONAL 0x80000000
40 static LPDIRECTINPUT
di;
43 #define DEFINE_STATIC_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
44 static const GUID _##name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
46 DEFINE_STATIC_GUID(GUID_SysMouse, 0x6F1D2B60, 0xD5A0, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00);
47 DEFINE_STATIC_GUID(GUID_XAxis, 0xA36D02E0, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00);
48 DEFINE_STATIC_GUID(GUID_YAxis, 0xA36D02E1, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00);
49 DEFINE_STATIC_GUID(GUID_ZAxis, 0xA36D02E2, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00);
52 { &_GUID_XAxis, DIMOFS_X, DIDFT_RELAXIS | DIDFT_ANYINSTANCE, 0 },
53 { &_GUID_YAxis, DIMOFS_Y, DIDFT_RELAXIS | DIDFT_ANYINSTANCE, 0 },
54 { &_GUID_ZAxis, DIMOFS_Z, DIDFT_RELAXIS | DIDFT_ANYINSTANCE |
DIDFT_OPTIONAL, 0 },
55 { NULL, DIMOFS_BUTTON0, DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
56 { NULL, DIMOFS_BUTTON1, DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
57 { NULL, DIMOFS_BUTTON2, DIDFT_BUTTON | DIDFT_ANYINSTANCE |
DIDFT_OPTIONAL, 0 },
58 { NULL, DIMOFS_BUTTON3, DIDFT_BUTTON | DIDFT_ANYINSTANCE |
DIDFT_OPTIONAL, 0 },
59 { NULL, DIMOFS_BUTTON4, DIDFT_BUTTON | DIDFT_ANYINSTANCE |
DIDFT_OPTIONAL, 0 },
60 { NULL, DIMOFS_BUTTON5, DIDFT_BUTTON | DIDFT_ANYINSTANCE |
DIDFT_OPTIONAL, 0 },
61 { NULL, DIMOFS_BUTTON6, DIDFT_BUTTON | DIDFT_ANYINSTANCE |
DIDFT_OPTIONAL, 0 },
62 { NULL, DIMOFS_BUTTON7, DIDFT_BUTTON | DIDFT_ANYINSTANCE |
DIDFT_OPTIONAL, 0 }
67 sizeof(DIOBJECTDATAFORMAT),
69 sizeof(DIMOUSESTATE2),
91 DIDEVICEOBJECTDATA data[16];
92 LPDIDEVICEOBJECTDATA p, last;
93 DWORD numElements, button;
103 hr = IDirectInputDevice_GetDeviceData(
di_mouse,
sizeof(data[0]), data, &numElements, 0);
104 if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) {
105 IDirectInputDevice_Acquire(
di_mouse);
109 Com_EPrintf(
"GetDeviceData failed with error 0x%lX\n", hr);
112 last = data + numElements;
113 for (p = data; p < last; p++) {
123 button = p->dwOfs - DIMOFS_BUTTON0;
124 if (p->dwData & 0x80) {
125 Key_Event(K_MOUSE1 + button, qtrue, p->dwTimeStamp);
127 Key_Event(K_MOUSE1 + button, qfalse, p->dwTimeStamp);
136 Key_Event(K_MWHEELUP, qtrue, p->dwTimeStamp);
137 Key_Event(K_MWHEELUP, qfalse, p->dwTimeStamp);
139 Key_Event(K_MWHEELDOWN, qtrue, p->dwTimeStamp);
140 Key_Event(K_MWHEELDOWN, qfalse, p->dwTimeStamp);
147 }
while (hr == DI_BUFFEROVERFLOW);
164 hr = IDirectInputDevice_GetDeviceState(
di_mouse,
sizeof(state), &state);
166 Com_EPrintf(
"GetDeviceState failed with error 0x%lX\n", hr);
182 Com_Printf(
"Shutting down DirectInput\n");
186 IDirectInputDevice_Unacquire(
di_mouse);
188 IDirectInputDevice_Release(
di_mouse);
192 IDirectInput_Release(
di);
213 Com_Printf(
"Initializing DirectInput\n");
218 Com_EPrintf(
"Failed to load dinput.dll\n");
225 Com_EPrintf(
"Failed to obtain DirectInputCreate\n");
232 Com_EPrintf(
"DirectInputCreate failed with error 0x%lX\n", hr);
236 hr = IDirectInput_CreateDevice(
di, &_GUID_SysMouse, &
di_mouse, NULL);
238 Com_EPrintf(
"CreateDevice failed with error 0x%lX\n", hr);
244 Com_EPrintf(
"SetDataFormat failed with error 0x%lX\n", hr);
248 hr = IDirectInputDevice_SetCooperativeLevel(
di_mouse,
win.wnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
250 Com_EPrintf(
"SetCooperativeLevel failed with error 0x%lX\n", hr);
256 Com_EPrintf(
"SetProperty failed with error 0x%lX\n", hr);
266 IDirectInputDevice_Release(
di_mouse);
270 IDirectInput_Release(
di);
293 if (grab == IN_GRAB) {
294 Com_DPrintf(
"IDirectInputDevice_Acquire\n");
295 hr = IDirectInputDevice_Acquire(
di_mouse);
297 Com_EPrintf(
"Failed to acquire mouse, error 0x%lX\n", hr);
300 Com_DPrintf(
"IDirectInputDevice_Unacquire\n");
301 hr = IDirectInputDevice_Unacquire(
di_mouse);
303 Com_EPrintf(
"Failed to unacquire mouse, error 0x%lX\n", hr);