2 #define WIN32_LEAN_AND_MEAN
12 extern void PumpMessages(void);
14 // These are to kludge up a bit my slightly broken GCC directx port.
16 #define E_FAIL (HRESULT)0x80004005L
19 #define SUCCEEDED(a) ((HRESULT)(a) >= 0)
26 extern void PumpMessages(void);
28 unsigned char WMKey_Handler_Ready=0;
32 LPDIRECTINPUTDEVICE g_lpdidKeybd;
37 static BOOL EnsureInit (void)
39 if (g_lpdidKeybd == NULL)
44 return g_lpdidKeybd != NULL;
51 keyd_fake_repeat=1;//direct input doesn't repeat. -MPM
53 // my kingdom, my kingdom for C++...
54 if (SUCCEEDED (hr = DirectInputCreate (GetModuleHandle (NULL), DIRECTINPUT_VERSION, &g_lpdi, NULL)))
56 if (SUCCEEDED (hr = IDirectInput_CreateDevice (g_lpdi, (void *)&GUID_SysKeyboard, &g_lpdidKeybd, NULL)))
60 dipdw.diph.dwSize = sizeof (DIPROPDWORD);
61 dipdw.diph.dwHeaderSize = sizeof (DIPROPHEADER);
63 dipdw.diph.dwHow = DIPH_DEVICE;
66 if (SUCCEEDED (hr = IDirectInputDevice_SetDataFormat (g_lpdidKeybd, &c_dfDIKeyboard)) &&
67 SUCCEEDED (hr = IDirectInputDevice_SetCooperativeLevel (g_lpdidKeybd, g_hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)) &&
68 SUCCEEDED (hr = IDirectInputDevice_SetProperty (g_lpdidKeybd, DIPROP_BUFFERSIZE, &dipdw.diph)) &&
69 SUCCEEDED (hr = IDirectInputDevice_Acquire (g_lpdidKeybd)))
72 WMKey_Handler_Ready = 1;
77 IDirectInputDevice_Release (g_lpdidKeybd);
84 void arch_key_close(void)
86 WMKey_Handler_Ready = 0;
87 if (g_lpdidKeybd != NULL)
89 IDirectInputDevice_Unacquire (g_lpdidKeybd);
90 IDirectInputDevice_Release (g_lpdidKeybd);
95 IDirectInput_Release (g_lpdi);
100 HRESULT ReadKey (DIDEVICEOBJECTDATA *pdidod)
104 if (g_lpdidKeybd == NULL)
106 hr = IDirectInputDevice_Acquire (g_lpdidKeybd);
109 hr = IDirectInputDevice_GetDeviceData (
115 if (SUCCEEDED (hr) && cElements != 1)
122 void UpdateState (DIDEVICEOBJECTDATA *pdidod)
124 generic_key_handler(pdidod->dwOfs,(pdidod->dwData & 0x80));
127 void keyboard_handler()
129 // static int peekmsgcount = 0;
130 DIDEVICEOBJECTDATA didod;
131 while (SUCCEEDED (ReadKey (&didod)))
133 UpdateState (&didod);
135 //added 02/20/99 by adb to prevent message overflow
136 //(this should probably go somewhere else...)
137 // if (++peekmsgcount == 64) // 64 = wild guess...
148 void arch_key_flush()
152 DWORD cElements = INFINITE;
154 IDirectInputDevice_GetDeviceData (
156 sizeof (DIDEVICEOBJECTDATA),
166 void arch_key_poll(void)