wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / dinput / tests / keyboard.c
blob1cd31e03187056f74b98178151d4067bd8141607
1 /*
2 * Copyright (c) 2005 Robert Reif
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define DIRECTINPUT_VERSION 0x0700
21 #define COBJMACROS
22 #include <windows.h>
24 #include <math.h>
25 #include <stdio.h>
26 #include <stdlib.h>
28 #include "wine/test.h"
29 #include "windef.h"
30 #include "wingdi.h"
31 #include "dinput.h"
33 /* to make things easier with PSDK without a dinput.lib */
34 static HRESULT (WINAPI *pDirectInputCreateA)(HINSTANCE,DWORD,IDirectInputA **,IUnknown *);
36 static void pump_messages(void)
38 MSG msg;
40 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
42 TranslateMessage(&msg);
43 DispatchMessageA(&msg);
47 static HKL activate_keyboard_layout(LANGID langid, HKL *hkl_orig)
49 HKL hkl, hkl_current;
50 char hkl_name[64];
52 sprintf(hkl_name, "%08x", langid);
53 trace("Loading keyboard layout %s\n", hkl_name);
54 hkl = LoadKeyboardLayoutA(hkl_name, 0);
55 if (!hkl)
57 win_skip("Unable to load keyboard layout %s\n", hkl_name);
58 return 0;
60 *hkl_orig = ActivateKeyboardLayout(hkl, 0);
61 ok(*hkl_orig != 0, "Unable to activate keyboard layout %s\n", hkl_name);
62 if (!*hkl_orig) return 0;
64 hkl_current = GetKeyboardLayout(0);
65 if (LOWORD(hkl_current) != langid)
67 /* FIXME: Wine can't activate different keyboard layouts.
68 * for testing purposes use this workaround:
69 * setxkbmap us && LANG=en_US.UTF-8 make test
70 * setxkbmap fr && LANG=fr_FR.UTF-8 make test
71 * setxkbmap de && LANG=de_DE.UTF-8 make test
73 skip("current %08x != langid %08x\n", LOWORD(hkl_current), langid);
74 return 0;
77 return hkl;
80 static void acquire_tests(IDirectInputA *pDI, HWND hwnd)
82 HRESULT hr;
83 IDirectInputDeviceA *pKeyboard;
84 BYTE kbd_state[256];
85 LONG custom_state[6];
86 int i;
87 DIOBJECTDATAFORMAT dodf[] =
89 { &GUID_Key, sizeof(LONG) * 0, DIDFT_MAKEINSTANCE(DIK_Q)|DIDFT_BUTTON, 0 },
90 { &GUID_Key, sizeof(LONG) * 1, DIDFT_MAKEINSTANCE(DIK_W)|DIDFT_BUTTON, 0 },
91 { &GUID_Key, sizeof(LONG) * 2, DIDFT_MAKEINSTANCE(DIK_E)|DIDFT_BUTTON, 0 },
92 { &GUID_Key, sizeof(LONG) * 4, DIDFT_MAKEINSTANCE(DIK_R)|DIDFT_BUTTON, 0 },
94 DIDATAFORMAT df;
95 HKL hkl, hkl_orig;
96 UINT prev_raw_devices_count, raw_devices_count;
98 hkl = activate_keyboard_layout(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), &hkl_orig);
99 if (!hkl) return;
101 df.dwSize = sizeof( df );
102 df.dwObjSize = sizeof( DIOBJECTDATAFORMAT );
103 df.dwFlags = DIDF_RELAXIS;
104 df.dwDataSize = sizeof( custom_state );
105 df.dwNumObjs = ARRAY_SIZE(dodf);
106 df.rgodf = dodf;
108 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
109 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
110 if (FAILED(hr)) return;
112 hr = IDirectInputDevice_SetDataFormat(pKeyboard, &c_dfDIKeyboard);
113 ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
114 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
115 ok(SUCCEEDED(hr), "IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr);
116 hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
117 ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState(10,) should have failed: %08x\n", hr);
118 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
119 ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState() should have failed: %08x\n", hr);
120 hr = IDirectInputDevice_Unacquire(pKeyboard);
121 ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have failed: %08x\n", hr);
122 hr = IDirectInputDevice_Acquire(pKeyboard);
123 ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
124 hr = IDirectInputDevice_Acquire(pKeyboard);
125 ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have failed: %08x\n", hr);
126 hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
127 ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(10,) should have failed: %08x\n", hr);
128 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
129 ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr);
130 hr = IDirectInputDevice_Unacquire(pKeyboard);
131 ok(SUCCEEDED(hr), "IDirectInputDevice_Uncquire() failed: %08x\n", hr);
132 hr = IDirectInputDevice_SetDataFormat( pKeyboard , &df );
133 ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
134 hr = IDirectInputDevice_Acquire(pKeyboard);
135 ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
136 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(custom_state), custom_state);
137 ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState(4,) failed: %08x\n", hr);
138 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
139 ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(256,) should have failed: %08x\n", hr);
141 memset(custom_state, 0x56, sizeof(custom_state));
142 IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(custom_state), custom_state);
143 for (i = 0; i < ARRAY_SIZE(custom_state); i++)
144 ok(custom_state[i] == 0, "Should be zeroed, got 0x%08x\n", custom_state[i]);
146 /* simulate some keyboard input */
147 SetFocus(hwnd);
148 pump_messages();
150 keybd_event('Q', 0, 0, 0);
151 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(custom_state), custom_state);
152 ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr);
153 if (!custom_state[0])
154 win_skip("Keyboard event not processed, skipping test\n");
155 else
157 /* unacquiring should reset the device state */
158 hr = IDirectInputDevice_Unacquire(pKeyboard);
159 ok(SUCCEEDED(hr), "IDirectInputDevice_Unacquire() failed: %08x\n", hr);
160 hr = IDirectInputDevice_Acquire(pKeyboard);
161 ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
162 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(custom_state), custom_state);
163 ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState failed: %08x\n", hr);
164 for (i = 0; i < ARRAY_SIZE(custom_state); i++)
165 ok(custom_state[i] == 0, "Should be zeroed, got 0x%08x\n", custom_state[i]);
167 keybd_event('Q', 0, KEYEVENTF_KEYUP, 0);
169 prev_raw_devices_count = 0;
170 GetRegisteredRawInputDevices(NULL, &prev_raw_devices_count, sizeof(RAWINPUTDEVICE));
171 ok(prev_raw_devices_count == 0 || broken(prev_raw_devices_count == 1) /* wxppro, w2003std */,
172 "Unexpected raw devices registered: %d\n", prev_raw_devices_count);
174 hr = IDirectInputDevice_Acquire(pKeyboard);
175 ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
177 raw_devices_count = 0;
178 GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE));
179 ok(raw_devices_count == prev_raw_devices_count,
180 "Unexpected raw devices registered: %d\n", raw_devices_count);
182 hr = IDirectInputDevice_Unacquire(pKeyboard);
183 ok(SUCCEEDED(hr), "IDirectInputDevice_Unacquire() failed: %08x\n", hr);
185 IUnknown_Release(pKeyboard);
187 ActivateKeyboardLayout(hkl_orig, 0);
188 UnloadKeyboardLayout(hkl);
191 static const HRESULT SetCoop_null_window[16] = {
192 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
193 E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
194 E_INVALIDARG, E_HANDLE, S_OK, E_INVALIDARG,
195 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
197 static const HRESULT SetCoop_invalid_window[16] = {
198 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
199 E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
200 E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
201 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
203 static const HRESULT SetCoop_real_window[16] = {
204 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
205 E_INVALIDARG, S_OK, S_OK, E_INVALIDARG,
206 E_INVALIDARG, E_NOTIMPL, S_OK, E_INVALIDARG,
207 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
209 static const HRESULT SetCoop_child_window[16] = {
210 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
211 E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
212 E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
213 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
215 static void test_set_coop(IDirectInputA *pDI, HWND hwnd)
217 HRESULT hr;
218 IDirectInputDeviceA *pKeyboard = NULL;
219 int i;
220 HWND child;
222 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
223 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
224 if (FAILED(hr)) return;
226 for (i=0; i<16; i++)
228 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, i);
229 ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %08x\n", i, hr);
231 for (i=0; i<16; i++)
233 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, (HWND)0x400000, i);
234 ok(hr == SetCoop_invalid_window[i], "SetCooperativeLevel(invalid, %d): %08x\n", i, hr);
236 for (i=0; i<16; i++)
238 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, hwnd, i);
239 ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %08x\n", i, hr);
242 child = CreateWindowA("static", "Title", WS_CHILD | WS_VISIBLE, 10, 10, 50, 50, hwnd, NULL,
243 NULL, NULL);
244 ok(child != NULL, "err: %d\n", GetLastError());
246 for (i=0; i<16; i++)
248 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, child, i);
249 ok(hr == SetCoop_child_window[i], "SetCooperativeLevel(child, %d): %08x\n", i, hr);
252 DestroyWindow(child);
253 if (pKeyboard) IUnknown_Release(pKeyboard);
256 static void test_get_prop(IDirectInputA *pDI, HWND hwnd)
258 HRESULT hr;
259 IDirectInputDeviceA *pKeyboard = NULL;
260 DIPROPRANGE diprg;
261 DIPROPDWORD vidpid;
263 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
264 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
265 if (FAILED(hr)) return;
267 memset(&diprg, 0, sizeof(diprg));
268 diprg.diph.dwSize = sizeof(DIPROPRANGE);
269 diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
270 diprg.diph.dwHow = DIPH_DEVICE;
271 diprg.diph.dwObj = 0;
273 hr = IDirectInputDevice_GetProperty(pKeyboard, DIPROP_RANGE, &diprg.diph);
274 ok(hr == DIERR_UNSUPPORTED, "IDirectInputDevice_GetProperty() did not return DIPROP_RANGE but: %08x\n", hr);
276 memset(&vidpid, 0, sizeof(vidpid));
277 vidpid.diph.dwSize = sizeof(DIPROPDWORD);
278 vidpid.diph.dwHeaderSize = sizeof(DIPROPHEADER);
279 vidpid.diph.dwHow = DIPH_DEVICE;
280 vidpid.diph.dwObj = 0;
282 hr = IDirectInputDevice_GetProperty(pKeyboard, DIPROP_VIDPID, &vidpid.diph);
283 ok(hr == DIERR_UNSUPPORTED, "got %08x\n", hr);
285 IUnknown_Release(pKeyboard);
288 static void test_capabilities(IDirectInputA *pDI, HWND hwnd)
290 HRESULT hr;
291 IDirectInputDeviceA *pKeyboard = NULL;
292 DIDEVCAPS caps;
293 int kbd_type, kbd_subtype, dev_subtype;
295 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
296 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
297 if (FAILED(hr)) return;
299 caps.dwSize = sizeof(caps);
300 hr = IDirectInputDevice_GetCapabilities(pKeyboard, &caps);
302 ok (SUCCEEDED(hr), "GetCapabilities failed: 0x%08x\n", hr);
303 ok (caps.dwFlags & DIDC_ATTACHED, "GetCapabilities dwFlags: 0x%08x\n", caps.dwFlags);
304 ok (GET_DIDEVICE_TYPE(caps.dwDevType) == DIDEVTYPE_KEYBOARD,
305 "GetCapabilities invalid device type for dwDevType: 0x%08x\n", caps.dwDevType);
306 kbd_type = GetKeyboardType(0);
307 kbd_subtype = GetKeyboardType(1);
308 dev_subtype = GET_DIDEVICE_SUBTYPE(caps.dwDevType);
309 if (kbd_type == 4 || (kbd_type == 7 && kbd_subtype == 0))
310 ok (dev_subtype == DIDEVTYPEKEYBOARD_PCENH,
311 "GetCapabilities invalid device subtype for dwDevType: 0x%08x (%04x:%04x)\n",
312 caps.dwDevType, kbd_type, kbd_subtype);
313 else if (kbd_type == 7 && kbd_subtype == 2)
314 ok (dev_subtype == DIDEVTYPEKEYBOARD_JAPAN106,
315 "GetCapabilities invalid device subtype for dwDevType: 0x%08x (%04x:%04x)\n",
316 caps.dwDevType, kbd_type, kbd_subtype);
317 else
318 ok (dev_subtype != DIDEVTYPEKEYBOARD_UNKNOWN,
319 "GetCapabilities invalid device subtype for dwDevType: 0x%08x (%04x:%04x)\n",
320 caps.dwDevType, kbd_type, kbd_subtype);
322 IUnknown_Release(pKeyboard);
325 static void test_dik_codes(IDirectInputA *dI, HWND hwnd, LANGID langid)
327 static const struct key2dik
329 BYTE key, dik, todo;
330 } key2dik_en[] =
332 {'Q',DIK_Q}, {'W',DIK_W}, {'E',DIK_E}, {'R',DIK_R}, {'T',DIK_T}, {'Y',DIK_Y},
333 {'[',DIK_LBRACKET}, {']',DIK_RBRACKET}, {'.',DIK_PERIOD}
335 key2dik_fr[] =
337 {'A',DIK_Q}, {'Z',DIK_W}, {'E',DIK_E}, {'R',DIK_R}, {'T',DIK_T}, {'Y',DIK_Y},
338 {'^',DIK_LBRACKET}, {'$',DIK_RBRACKET}, {':',DIK_PERIOD}
340 key2dik_de[] =
342 {'Q',DIK_Q}, {'W',DIK_W}, {'E',DIK_E}, {'R',DIK_R}, {'T',DIK_T}, {'Z',DIK_Y},
343 {'\xfc',DIK_LBRACKET,1}, {'+',DIK_RBRACKET}, {'.',DIK_PERIOD}
345 key2dik_ja[] =
347 {'Q',DIK_Q}, {'W',DIK_W}, {'E',DIK_E}, {'R',DIK_R}, {'T',DIK_T}, {'Y',DIK_Y},
348 {'@',DIK_AT}, {']',DIK_RBRACKET}, {'.',DIK_PERIOD}
350 static const struct
352 LANGID langid;
353 const struct key2dik *map;
354 DWORD type;
355 } expected[] =
357 { MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
358 key2dik_en, DIDEVTYPEKEYBOARD_PCENH },
359 { MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH),
360 key2dik_fr, DIDEVTYPEKEYBOARD_PCENH },
361 { MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN),
362 key2dik_de, DIDEVTYPEKEYBOARD_PCENH },
363 { MAKELANGID(LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN),
364 key2dik_ja, DIDEVTYPEKEYBOARD_JAPAN106 }
366 const struct key2dik *map = NULL;
367 UINT i;
368 HRESULT hr;
369 IDirectInputDeviceA *device;
370 DIDEVCAPS caps;
371 HKL hkl, hkl_orig;
372 MSG msg;
374 for (i = 0; i < ARRAY_SIZE(expected); i++)
376 if (expected[i].langid == langid)
378 map = expected[i].map;
379 break;
382 ok(map != NULL, "can't find mapping for langid %04x\n", langid);
383 if (!map) return;
385 hr = IDirectInput_CreateDevice(dI, &GUID_SysKeyboard, &device, NULL);
386 ok(hr == S_OK, "CreateDevice() failed: %08x\n", hr);
387 hr = IDirectInputDevice_SetDataFormat(device, &c_dfDIKeyboard);
388 ok(hr == S_OK, "SetDataFormat() failed: %08x\n", hr);
389 hr = IDirectInputDevice_Acquire(device);
390 ok(hr == S_OK, "Acquire() failed: %08x\n", hr);
391 caps.dwSize = sizeof( caps );
392 hr = IDirectInputDevice_GetCapabilities(device, &caps);
393 ok(hr == S_OK, "GetDeviceInstance() failed: %08x\n", hr);
394 if (expected[i].type != GET_DIDEVICE_SUBTYPE(caps.dwDevType)) {
395 skip("Keyboard type(%u) doesn't match for lang %04x\n",
396 GET_DIDEVICE_SUBTYPE(caps.dwDevType), langid);
397 goto fail;
400 hkl = activate_keyboard_layout(langid, &hkl_orig);
401 if (!hkl) goto fail;
403 SetFocus(hwnd);
404 pump_messages();
406 for (i = 0; i < ARRAY_SIZE(key2dik_en); i++)
408 BYTE kbd_state[256];
409 UINT n;
410 WORD vkey, scan;
411 INPUT in;
413 n = VkKeyScanExW(map[i].key, hkl);
414 todo_wine_if(map[i].todo & 1)
415 ok(n != 0xffff, "%u: failed to get virtual key value for %c(%02x)\n", i, map[i].key, map[i].key);
416 vkey = LOBYTE(n);
417 n = MapVirtualKeyExA(vkey, MAPVK_VK_TO_CHAR, hkl) & 0xff;
418 todo_wine_if(map[i].todo & 1)
419 ok(n == map[i].key, "%u: expected %c(%02x), got %c(%02x)\n", i, map[i].key, map[i].key, n, n);
420 scan = MapVirtualKeyExA(vkey, MAPVK_VK_TO_VSC, hkl);
421 /* scan codes match the DIK_ codes on US keyboard.
422 however, it isn't true for symbols and punctuations in other layouts. */
423 if (isalpha(map[i].key) || langid == MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT))
424 ok(scan == map[i].dik, "%u: expected %02x, got %02x\n", i, map[i].dik, n);
425 else
426 todo_wine_if(map[i].todo & 1)
427 ok(scan, "%u: fail to get scan code value, expected %02x (vkey=%02x)\n",
428 i, map[i].dik, vkey);
430 in.type = INPUT_KEYBOARD;
431 U(in).ki.wVk = vkey;
432 U(in).ki.wScan = scan;
433 U(in).ki.dwFlags = 0;
434 U(in).ki.dwExtraInfo = 0;
435 U(in).ki.time = 0;
436 n = SendInput(1, &in, sizeof(in));
437 ok(n == 1, "got %u\n", n);
439 if (!PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE))
441 U(in).ki.dwFlags = KEYEVENTF_KEYUP;
442 SendInput(1, &in, sizeof(in));
443 win_skip("failed to queue keyboard event\n");
444 break;
446 ok(msg.message == WM_KEYDOWN, "expected WM_KEYDOWN, got %04x\n", msg.message);
447 DispatchMessageA(&msg);
449 n = MapVirtualKeyExA(msg.wParam, MAPVK_VK_TO_CHAR, hkl);
450 trace("keydown wParam: %#08lx (%c) lParam: %#08lx, MapVirtualKey(MAPVK_VK_TO_CHAR) = %c\n",
451 msg.wParam, isprint(LOWORD(msg.wParam)) ? LOWORD(msg.wParam) : '?',
452 msg.lParam, isprint(n) ? n : '?');
454 pump_messages();
456 hr = IDirectInputDevice_GetDeviceState(device, sizeof(kbd_state), kbd_state);
457 ok(hr == S_OK, "GetDeviceState() failed: %08x\n", hr);
459 /* this never happens on real hardware but tesbot VMs seem to have timing issues */
460 if (i == 0 && kbd_state[map[0].dik] != 0x80)
462 win_skip("dinput failed to handle keyboard event\n");
463 break;
466 todo_wine_if(map[i].todo)
467 ok(kbd_state[map[i].dik] == 0x80, "DI key %#x has state %#x\n", map[i].dik, kbd_state[map[i].dik]);
469 U(in).ki.dwFlags = KEYEVENTF_KEYUP;
470 n = SendInput(1, &in, sizeof(in));
471 ok(n == 1, "got %u\n", n);
473 pump_messages();
476 ActivateKeyboardLayout(hkl_orig, 0);
477 UnloadKeyboardLayout(hkl);
478 fail:
479 IDirectInputDevice_Unacquire(device);
480 IUnknown_Release(device);
483 static void test_GetDeviceInfo(IDirectInputA *pDI)
485 HRESULT hr;
486 IDirectInputDeviceA *pKey = NULL;
487 DIDEVICEINSTANCEA instA;
488 DIDEVICEINSTANCE_DX3A inst3A;
490 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKey, NULL);
491 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
492 if (FAILED(hr)) return;
494 instA.dwSize = sizeof(instA);
495 hr = IDirectInputDevice_GetDeviceInfo(pKey, &instA);
496 ok(SUCCEEDED(hr), "got %08x\n", hr);
498 inst3A.dwSize = sizeof(inst3A);
499 hr = IDirectInputDevice_GetDeviceInfo(pKey, (DIDEVICEINSTANCEA *)&inst3A);
500 ok(SUCCEEDED(hr), "got %08x\n", hr);
502 ok(instA.dwSize != inst3A.dwSize, "got %d, %d \n", instA.dwSize, inst3A.dwSize);
503 ok(IsEqualGUID(&instA.guidInstance, &inst3A.guidInstance), "got %s, %s\n",
504 wine_dbgstr_guid(&instA.guidInstance), wine_dbgstr_guid(&inst3A.guidInstance) );
505 ok(IsEqualGUID(&instA.guidProduct, &inst3A.guidProduct), "got %s, %s\n",
506 wine_dbgstr_guid(&instA.guidProduct), wine_dbgstr_guid(&inst3A.guidProduct) );
507 ok(instA.dwDevType == inst3A.dwDevType, "got %d, %d\n", instA.dwDevType, inst3A.dwDevType);
509 IUnknown_Release(pKey);
512 static void keyboard_tests(DWORD version)
514 HRESULT hr;
515 IDirectInputA *pDI = NULL;
516 HINSTANCE hInstance = GetModuleHandleW(NULL);
517 HWND hwnd;
518 ULONG ref = 0;
520 hr = pDirectInputCreateA(hInstance, version, &pDI, NULL);
521 if (hr == DIERR_OLDDIRECTINPUTVERSION)
523 skip("Tests require a newer dinput version\n");
524 return;
526 ok(SUCCEEDED(hr), "DirectInputCreateA() failed: %08x\n", hr);
527 if (FAILED(hr)) return;
529 hwnd = CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 10, 10, 200, 200,
530 NULL, NULL, NULL, NULL);
531 ok(hwnd != NULL, "err: %d\n", GetLastError());
532 SetForegroundWindow( hwnd );
534 if (hwnd)
536 pump_messages();
538 acquire_tests(pDI, hwnd);
539 test_set_coop(pDI, hwnd);
540 test_get_prop(pDI, hwnd);
541 test_capabilities(pDI, hwnd);
542 test_GetDeviceInfo(pDI);
544 test_dik_codes(pDI, hwnd, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT));
545 test_dik_codes(pDI, hwnd, MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH));
546 test_dik_codes(pDI, hwnd, MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN));
547 test_dik_codes(pDI, hwnd, MAKELANGID(LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN));
550 DestroyWindow(hwnd);
551 if (pDI) ref = IUnknown_Release(pDI);
552 ok(!ref, "IDirectInput_Release() reference count = %d\n", ref);
555 START_TEST(keyboard)
557 pDirectInputCreateA = (void *)GetProcAddress(GetModuleHandleA("dinput.dll"), "DirectInputCreateA");
559 CoInitialize(NULL);
561 keyboard_tests(0x0700);
563 CoUninitialize();