ReactOS 0.4.15-dev-5664-g3bf4ef6
keyboard.c File Reference
#include <windows.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "wine/test.h"
#include "windef.h"
#include "wingdi.h"
#include "dinput.h"
Include dependency graph for keyboard.c:

Go to the source code of this file.

Macros

#define DIRECTINPUT_VERSION   0x0700
 
#define COBJMACROS
 

Functions

static HRESULT (WINAPI *pDirectInputCreateA)(HINSTANCE
 
static IDirectInputA IUnknown *static void pump_messages (void)
 
static HKL activate_keyboard_layout (LANGID langid, HKL *hkl_orig)
 
static void acquire_tests (IDirectInputA *pDI, HWND hwnd)
 
static void test_set_coop (IDirectInputA *pDI, HWND hwnd)
 
static void test_get_prop (IDirectInputA *pDI, HWND hwnd)
 
static void test_capabilities (IDirectInputA *pDI, HWND hwnd)
 
static void test_dik_codes (IDirectInputA *dI, HWND hwnd, LANGID langid)
 
static void test_GetDeviceInfo (IDirectInputA *pDI)
 
static void keyboard_tests (DWORD version)
 
 START_TEST (keyboard)
 

Variables

static DWORD
 
static const HRESULT SetCoop_null_window [16]
 
static const HRESULT SetCoop_invalid_window [16]
 
static const HRESULT SetCoop_real_window [16]
 
static const HRESULT SetCoop_child_window [16]
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file keyboard.c.

◆ DIRECTINPUT_VERSION

#define DIRECTINPUT_VERSION   0x0700

Definition at line 19 of file keyboard.c.

Function Documentation

◆ acquire_tests()

static void acquire_tests ( IDirectInputA *  pDI,
HWND  hwnd 
)
static

Definition at line 80 of file keyboard.c.

81{
82 HRESULT hr;
83 IDirectInputDeviceA *pKeyboard;
84 BYTE kbd_state[256];
85 LONG custom_state[6];
86 int i;
87 DIOBJECTDATAFORMAT dodf[] =
88 {
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 },
93 };
94 DIDATAFORMAT df;
95 HKL hkl, hkl_orig;
96 UINT prev_raw_devices_count, raw_devices_count;
97
99 if (!hkl) return;
100
101 df.dwSize = sizeof( df );
102 df.dwObjSize = sizeof( DIOBJECTDATAFORMAT );
104 df.dwDataSize = sizeof( custom_state );
105 df.dwNumObjs = ARRAY_SIZE(dodf);
106 df.rgodf = dodf;
107
108 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
109 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
110 if (FAILED(hr)) return;
111
113 ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
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);
140
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]);
145
146 /* simulate some keyboard input */
147 SetFocus(hwnd);
149
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
156 {
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]);
166 }
167 keybd_event('Q', 0, KEYEVENTF_KEYUP, 0);
168
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);
173
174 hr = IDirectInputDevice_Acquire(pKeyboard);
175 ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
176
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);
181
182 hr = IDirectInputDevice_Unacquire(pKeyboard);
183 ok(SUCCEEDED(hr), "IDirectInputDevice_Unacquire() failed: %08x\n", hr);
184
185 if (pKeyboard) IUnknown_Release(pKeyboard);
186
187 ActivateKeyboardLayout(hkl_orig, 0);
189}
#define broken(x)
Definition: _sntprintf.h:21
#define ok(value,...)
Definition: atltest.h:57
#define ARRAY_SIZE(a)
Definition: main.h:24
const DIDATAFORMAT c_dfDIKeyboard
Definition: data_formats.c:561
#define IDirectInputDevice_Acquire(p)
Definition: dinput.h:1608
#define IDirectInputDevice_SetDataFormat(p, a)
Definition: dinput.h:1612
#define DIERR_INVALIDPARAM
Definition: dinput.h:152
#define DIK_R
Definition: dinput.h:488
struct _DIOBJECTDATAFORMAT DIOBJECTDATAFORMAT
#define IDirectInputDevice_SetCooperativeLevel(p, a, b)
Definition: dinput.h:1614
#define DISCL_BACKGROUND
Definition: dinput.h:966
#define DIK_E
Definition: dinput.h:487
#define DIERR_NOTACQUIRED
Definition: dinput.h:167
#define IDirectInput_CreateDevice(p, a, b, c)
Definition: dinput.h:2296
#define DIDF_RELAXIS
Definition: dinput.h:776
#define DIK_W
Definition: dinput.h:486
#define DIDFT_MAKEINSTANCE(n)
Definition: dinput.h:762
#define IDirectInputDevice_Unacquire(p)
Definition: dinput.h:1609
#define DISCL_NONEXCLUSIVE
Definition: dinput.h:964
#define IDirectInputDevice_GetDeviceState(p, a, b)
Definition: dinput.h:1610
#define DIK_Q
Definition: dinput.h:485
#define DIDFT_BUTTON
Definition: dinput.h:756
#define NULL
Definition: types.h:112
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
static HKL activate_keyboard_layout(LANGID langid, HKL *hkl_orig)
Definition: keyboard.c:47
static IDirectInputA IUnknown *static void pump_messages(void)
Definition: keyboard.c:36
HKL hkl
Definition: msctf.idl:611
UINT_PTR HKL
Definition: msctf.idl:104
unsigned int UINT
Definition: ndis.h:50
long LONG
Definition: pedump.c:60
#define MAKELANGID(p, s)
Definition: nls.h:15
#define LANG_ENGLISH
Definition: nls.h:52
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define win_skip
Definition: test.h:160
#define memset(x, y, z)
Definition: compat.h:39
HRESULT hr
Definition: shlfolder.c:183
LPDIOBJECTDATAFORMAT rgodf
Definition: dinput.h:813
DWORD dwFlags
Definition: dinput.h:810
DWORD dwSize
Definition: dinput.h:808
DWORD dwObjSize
Definition: dinput.h:809
DWORD dwDataSize
Definition: dinput.h:811
DWORD dwNumObjs
Definition: dinput.h:812
UINT WINAPI DECLSPEC_HOTPATCH GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, PUINT puiNumDevices, UINT cbSize)
Definition: stubs.c:349
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define S_FALSE
Definition: winerror.h:2357
BOOL WINAPI UnloadKeyboardLayout(_In_ HKL)
HWND WINAPI SetFocus(_In_opt_ HWND)
VOID WINAPI keybd_event(_In_ BYTE, _In_ BYTE, _In_ DWORD, _In_ ULONG_PTR)
HKL WINAPI ActivateKeyboardLayout(_In_ HKL, _In_ UINT)
#define KEYEVENTF_KEYUP
Definition: winuser.h:1096
unsigned char BYTE
Definition: xxhash.c:193

Referenced by keyboard_tests().

◆ activate_keyboard_layout()

static HKL activate_keyboard_layout ( LANGID  langid,
HKL hkl_orig 
)
static

Definition at line 47 of file keyboard.c.

48{
49 HKL hkl, hkl_current;
50 char hkl_name[64];
51
52 sprintf(hkl_name, "%08x", langid);
53 trace("Loading keyboard layout %s\n", hkl_name);
54 hkl = LoadKeyboardLayoutA(hkl_name, 0);
55 if (!hkl)
56 {
57 win_skip("Unable to load keyboard layout %s\n", hkl_name);
58 return 0;
59 }
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;
63
64 hkl_current = GetKeyboardLayout(0);
65 if (LOWORD(hkl_current) != langid)
66 {
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
72 */
73 skip("current %08x != langid %08x\n", LOWORD(hkl_current), langid);
74 return 0;
75 }
76
77 return hkl;
78}
#define trace
Definition: atltest.h:70
#define skip(...)
Definition: atltest.h:64
PKEYBOARD_LAYOUT GetKeyboardLayout()
Definition: utils.c:194
#define sprintf(buf, format,...)
Definition: sprintf.c:55
LANGID langid
Definition: msctf.idl:605
#define LOWORD(l)
Definition: pedump.c:82
HKL WINAPI LoadKeyboardLayoutA(_In_ LPCSTR, _In_ UINT)

Referenced by acquire_tests(), and test_dik_codes().

◆ HRESULT()

static HRESULT ( WINAPI pDirectInputCreateA)
static

◆ keyboard_tests()

static void keyboard_tests ( DWORD  version)
static

Definition at line 502 of file keyboard.c.

503{
504 HRESULT hr;
505 IDirectInputA *pDI = NULL;
507 HWND hwnd;
508 ULONG ref = 0;
509
510 hr = pDirectInputCreateA(hInstance, version, &pDI, NULL);
512 {
513 skip("Tests require a newer dinput version\n");
514 return;
515 }
516 ok(SUCCEEDED(hr), "DirectInputCreateA() failed: %08x\n", hr);
517 if (FAILED(hr)) return;
518
519 hwnd = CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 10, 10, 200, 200,
520 NULL, NULL, NULL, NULL);
521 ok(hwnd != NULL, "err: %d\n", GetLastError());
523
524 if (hwnd)
525 {
527
528 acquire_tests(pDI, hwnd);
529 test_set_coop(pDI, hwnd);
530 test_get_prop(pDI, hwnd);
533
538 }
539
541 if (pDI) ref = IUnknown_Release(pDI);
542 ok(!ref, "IDirectInput_Release() reference count = %d\n", ref);
543}
HINSTANCE hInstance
Definition: charmap.c:19
#define DIERR_OLDDIRECTINPUTVERSION
Definition: dinput.h:141
static const WCHAR version[]
Definition: asmname.c:66
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
unsigned int ULONG
Definition: retypes.h:1
static void test_capabilities(IDirectInputA *pDI, HWND hwnd)
Definition: keyboard.c:278
static void test_GetDeviceInfo(IDirectInputA *pDI)
Definition: keyboard.c:473
static void test_dik_codes(IDirectInputA *dI, HWND hwnd, LANGID langid)
Definition: keyboard.c:315
static void acquire_tests(IDirectInputA *pDI, HWND hwnd)
Definition: keyboard.c:80
static void test_set_coop(IDirectInputA *pDI, HWND hwnd)
Definition: keyboard.c:215
static void test_get_prop(IDirectInputA *pDI, HWND hwnd)
Definition: keyboard.c:256
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define WS_VISIBLE
Definition: pedump.c:620
#define SUBLANG_JAPANESE_JAPAN
Definition: nls.h:271
#define SUBLANG_FRENCH
Definition: nls.h:242
#define LANG_GERMAN
Definition: nls.h:62
#define SUBLANG_GERMAN
Definition: nls.h:251
#define LANG_JAPANESE
Definition: nls.h:76
#define LANG_FRENCH
Definition: nls.h:58
Definition: send.c:48
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4305
BOOL WINAPI SetForegroundWindow(_In_ HWND)
BOOL WINAPI DestroyWindow(_In_ HWND)

Referenced by START_TEST().

◆ pump_messages()

static IDirectInputA IUnknown *static void pump_messages ( void  )
static

Definition at line 36 of file keyboard.c.

37{
38 MSG msg;
39
40 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
41 {
44 }
45}
#define msg(x)
Definition: auth_time.c:54
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define PM_REMOVE
Definition: winuser.h:1186
BOOL WINAPI PeekMessageA(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)

Referenced by acquire_tests(), keyboard_tests(), and test_dik_codes().

◆ START_TEST()

START_TEST ( keyboard  )

Definition at line 545 of file keyboard.c.

546{
547 pDirectInputCreateA = (void *)GetProcAddress(GetModuleHandleA("dinput.dll"), "DirectInputCreateA");
548
550
551 keyboard_tests(0x0700);
552
554}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
static void keyboard_tests(DWORD version)
Definition: keyboard.c:502

◆ test_capabilities()

static void test_capabilities ( IDirectInputA *  pDI,
HWND  hwnd 
)
static

Definition at line 278 of file keyboard.c.

279{
280 HRESULT hr;
281 IDirectInputDeviceA *pKeyboard = NULL;
282 DIDEVCAPS caps;
283 int kbd_type, kbd_subtype, dev_subtype;
284
285 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
286 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
287 if (FAILED(hr)) return;
288
289 caps.dwSize = sizeof(caps);
290 hr = IDirectInputDevice_GetCapabilities(pKeyboard, &caps);
291
292 ok (SUCCEEDED(hr), "GetCapabilities failed: 0x%08x\n", hr);
293 ok (caps.dwFlags & DIDC_ATTACHED, "GetCapabilities dwFlags: 0x%08x\n", caps.dwFlags);
295 "GetCapabilities invalid device type for dwDevType: 0x%08x\n", caps.dwDevType);
296 kbd_type = GetKeyboardType(0);
297 kbd_subtype = GetKeyboardType(1);
298 dev_subtype = GET_DIDEVICE_SUBTYPE(caps.dwDevType);
299 if (kbd_type == 4 || (kbd_type == 7 && kbd_subtype == 0))
300 ok (dev_subtype == DIDEVTYPEKEYBOARD_PCENH,
301 "GetCapabilities invalid device subtype for dwDevType: 0x%08x (%04x:%04x)\n",
302 caps.dwDevType, kbd_type, kbd_subtype);
303 else if (kbd_type == 7 && kbd_subtype == 2)
304 ok (dev_subtype == DIDEVTYPEKEYBOARD_JAPAN106,
305 "GetCapabilities invalid device subtype for dwDevType: 0x%08x (%04x:%04x)\n",
306 caps.dwDevType, kbd_type, kbd_subtype);
307 else
308 ok (dev_subtype != DIDEVTYPEKEYBOARD_UNKNOWN,
309 "GetCapabilities invalid device subtype for dwDevType: 0x%08x (%04x:%04x)\n",
310 caps.dwDevType, kbd_type, kbd_subtype);
311
312 IUnknown_Release(pKeyboard);
313}
#define DIDEVTYPEKEYBOARD_JAPAN106
Definition: dinput.h:238
#define DIDEVTYPE_KEYBOARD
Definition: dinput.h:199
#define DIDC_ATTACHED
Definition: dinput.h:945
#define IDirectInputDevice_GetCapabilities(p, a)
Definition: dinput.h:1604
#define GET_DIDEVICE_SUBTYPE(dwDevType)
Definition: dinput.h:321
#define DIDEVTYPEKEYBOARD_PCENH
Definition: dinput.h:232
#define DIDEVTYPEKEYBOARD_UNKNOWN
Definition: dinput.h:228
#define GET_DIDEVICE_TYPE(dwDevType)
Definition: dinput.h:320
DWORD dwSize
Definition: dinput.h:932
DWORD dwFlags
Definition: dinput.h:933
DWORD dwDevType
Definition: dinput.h:934
int WINAPI GetKeyboardType(_In_ int)

Referenced by keyboard_tests().

◆ test_dik_codes()

static void test_dik_codes ( IDirectInputA *  dI,
HWND  hwnd,
LANGID  langid 
)
static

Definition at line 315 of file keyboard.c.

316{
317 static const struct key2dik
318 {
319 BYTE key, dik, todo;
320 } key2dik_en[] =
321 {
322 {'Q',DIK_Q}, {'W',DIK_W}, {'E',DIK_E}, {'R',DIK_R}, {'T',DIK_T}, {'Y',DIK_Y},
323 {'[',DIK_LBRACKET}, {']',DIK_RBRACKET}, {'.',DIK_PERIOD}
324 },
325 key2dik_fr[] =
326 {
327 {'A',DIK_Q}, {'Z',DIK_W}, {'E',DIK_E}, {'R',DIK_R}, {'T',DIK_T}, {'Y',DIK_Y},
328 {'^',DIK_LBRACKET}, {'$',DIK_RBRACKET}, {':',DIK_PERIOD}
329 },
330 key2dik_de[] =
331 {
332 {'Q',DIK_Q}, {'W',DIK_W}, {'E',DIK_E}, {'R',DIK_R}, {'T',DIK_T}, {'Z',DIK_Y},
333 {'\xfc',DIK_LBRACKET,1}, {'+',DIK_RBRACKET}, {'.',DIK_PERIOD}
334 },
335 key2dik_ja[] =
336 {
337 {'Q',DIK_Q}, {'W',DIK_W}, {'E',DIK_E}, {'R',DIK_R}, {'T',DIK_T}, {'Y',DIK_Y},
338 {'@',DIK_AT}, {']',DIK_RBRACKET}, {'.',DIK_PERIOD}
339 };
340 static const struct
341 {
343 const struct key2dik *map;
344 DWORD type;
345 } expected[] =
346 {
348 key2dik_en, DIDEVTYPEKEYBOARD_PCENH },
350 key2dik_fr, DIDEVTYPEKEYBOARD_PCENH },
352 key2dik_de, DIDEVTYPEKEYBOARD_PCENH },
354 key2dik_ja, DIDEVTYPEKEYBOARD_JAPAN106 }
355 };
356 const struct key2dik *map = NULL;
357 UINT i;
358 HRESULT hr;
359 IDirectInputDeviceA *device;
360 DIDEVCAPS caps;
361 HKL hkl, hkl_orig;
362 MSG msg;
363
364 for (i = 0; i < ARRAY_SIZE(expected); i++)
365 {
366 if (expected[i].langid == langid)
367 {
368 map = expected[i].map;
369 break;
370 }
371 }
372 ok(map != NULL, "can't find mapping for langid %04x\n", langid);
373 if (!map) return;
374
375 hr = IDirectInput_CreateDevice(dI, &GUID_SysKeyboard, &device, NULL);
376 ok(hr == S_OK, "CreateDevice() failed: %08x\n", hr);
378 ok(hr == S_OK, "SetDataFormat() failed: %08x\n", hr);
380 ok(hr == S_OK, "Acquire() failed: %08x\n", hr);
381 caps.dwSize = sizeof( caps );
383 ok(hr == S_OK, "GetDeviceInstance() failed: %08x\n", hr);
385 skip("Keyboard type(%u) doesn't match for lang %04x\n",
387 goto fail;
388 }
389
390 hkl = activate_keyboard_layout(langid, &hkl_orig);
391 if (!hkl) goto fail;
392
393 SetFocus(hwnd);
395
396 for (i = 0; i < ARRAY_SIZE(key2dik_en); i++)
397 {
398 BYTE kbd_state[256];
399 UINT n;
400 WORD vkey, scan;
401 INPUT in;
402
403 n = VkKeyScanExW(map[i].key, hkl);
404 todo_wine_if(map[i].todo & 1)
405 ok(n != 0xffff, "%u: failed to get virtual key value for %c(%02x)\n", i, map[i].key, map[i].key);
406 vkey = LOBYTE(n);
407 n = MapVirtualKeyExA(vkey, MAPVK_VK_TO_CHAR, hkl) & 0xff;
408 todo_wine_if(map[i].todo & 1)
409 ok(n == map[i].key, "%u: expected %c(%02x), got %c(%02x)\n", i, map[i].key, map[i].key, n, n);
410 scan = MapVirtualKeyExA(vkey, MAPVK_VK_TO_VSC, hkl);
411 /* scan codes match the DIK_ codes on US keyboard.
412 however, it isn't true for symbols and punctuations in other layouts. */
414 ok(scan == map[i].dik, "%u: expected %02x, got %02x\n", i, map[i].dik, n);
415 else
416 todo_wine_if(map[i].todo & 1)
417 ok(scan, "%u: fail to get scan code value, expected %02x (vkey=%02x)\n",
418 i, map[i].dik, vkey);
419
420 in.type = INPUT_KEYBOARD;
421 U(in).ki.wVk = vkey;
422 U(in).ki.wScan = scan;
423 U(in).ki.dwFlags = 0;
424 U(in).ki.dwExtraInfo = 0;
425 U(in).ki.time = 0;
426 n = SendInput(1, &in, sizeof(in));
427 ok(n == 1, "got %u\n", n);
428
429 if (!PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE))
430 {
431 U(in).ki.dwFlags = KEYEVENTF_KEYUP;
432 SendInput(1, &in, sizeof(in));
433 win_skip("failed to queue keyboard event\n");
434 break;
435 }
436 ok(msg.message == WM_KEYDOWN, "expected WM_KEYDOWN, got %04x\n", msg.message);
438
440 trace("keydown wParam: %#08lx (%c) lParam: %#08lx, MapVirtualKey(MAPVK_VK_TO_CHAR) = %c\n",
441 msg.wParam, isprint(LOWORD(msg.wParam)) ? LOWORD(msg.wParam) : '?',
442 msg.lParam, isprint(n) ? n : '?');
443
445
446 hr = IDirectInputDevice_GetDeviceState(device, sizeof(kbd_state), kbd_state);
447 ok(hr == S_OK, "GetDeviceState() failed: %08x\n", hr);
448
449 /* this never happens on real hardware but tesbot VMs seem to have timing issues */
450 if (i == 0 && kbd_state[map[0].dik] != 0x80)
451 {
452 win_skip("dinput failed to handle keyboard event\n");
453 break;
454 }
455
457 ok(kbd_state[map[i].dik] == 0x80, "DI key %#x has state %#x\n", map[i].dik, kbd_state[map[i].dik]);
458
459 U(in).ki.dwFlags = KEYEVENTF_KEYUP;
460 n = SendInput(1, &in, sizeof(in));
461 ok(n == 1, "got %u\n", n);
462
464 }
465
466 ActivateKeyboardLayout(hkl_orig, 0);
468fail:
470 IUnknown_Release(device);
471}
#define isalpha(c)
Definition: acclib.h:74
#define isprint(c)
Definition: acclib.h:73
#define U(x)
Definition: wordpad.c:45
Definition: _map.h:48
#define DIK_PERIOD
Definition: dinput.h:521
#define DIK_T
Definition: dinput.h:489
#define DIK_RBRACKET
Definition: dinput.h:496
#define DIK_Y
Definition: dinput.h:490
#define DIK_LBRACKET
Definition: dinput.h:495
#define DIK_AT
Definition: dinput.h:564
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLdouble n
Definition: glext.h:7729
GLuint in
Definition: glext.h:9616
#define S_OK
Definition: intsafe.h:52
#define LOBYTE(W)
Definition: jmemdos.c:487
BOOL todo
Definition: filedlg.c:313
BOOL expected
Definition: store.c:2063
#define todo_wine_if(is_todo)
Definition: custom.c:76
Definition: devices.h:37
Definition: copy.c:22
WORD LANGID
Definition: typedefs.h:81
UINT WINAPI SendInput(UINT, LPINPUT, int)
Definition: ntwrapper.h:344
#define INPUT_KEYBOARD
Definition: winable.h:10
UINT WINAPI MapVirtualKeyExA(_In_ UINT, _In_ UINT, _In_opt_ HKL)
SHORT WINAPI VkKeyScanExW(_In_ WCHAR, _In_ HKL)
#define MAPVK_VK_TO_CHAR
Definition: winuser.h:2347
#define MAPVK_VK_TO_VSC
Definition: winuser.h:2345
#define WM_KEYDOWN
Definition: winuser.h:1705

Referenced by keyboard_tests().

◆ test_get_prop()

static void test_get_prop ( IDirectInputA *  pDI,
HWND  hwnd 
)
static

Definition at line 256 of file keyboard.c.

257{
258 HRESULT hr;
259 IDirectInputDeviceA *pKeyboard = NULL;
260 DIPROPRANGE diprg;
261
262 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
263 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
264 if (FAILED(hr)) return;
265
266 memset(&diprg, 0, sizeof(diprg));
267 diprg.diph.dwSize = sizeof(DIPROPRANGE);
268 diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
269 diprg.diph.dwHow = DIPH_DEVICE;
270 diprg.diph.dwObj = 0;
271
273 ok(hr == DIERR_UNSUPPORTED, "IDirectInputDevice_GetProperty() did not return DIPROP_RANGE but: %08x\n", hr);
274
275 if (pKeyboard) IUnknown_Release(pKeyboard);
276}
#define DIPROP_RANGE
Definition: dinput.h:892
#define IDirectInputDevice_GetProperty(p, a, b)
Definition: dinput.h:1606
#define DIERR_UNSUPPORTED
Definition: dinput.h:156
#define DIPH_DEVICE
Definition: dinput.h:835
DWORD dwObj
Definition: dinput.h:830
DWORD dwSize
Definition: dinput.h:828
DWORD dwHeaderSize
Definition: dinput.h:829
DWORD dwHow
Definition: dinput.h:831
DIPROPHEADER diph
Definition: dinput.h:849

Referenced by keyboard_tests().

◆ test_GetDeviceInfo()

static void test_GetDeviceInfo ( IDirectInputA *  pDI)
static

Definition at line 473 of file keyboard.c.

474{
475 HRESULT hr;
476 IDirectInputDeviceA *pKey = NULL;
477 DIDEVICEINSTANCEA instA;
479
480 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKey, NULL);
481 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
482 if (FAILED(hr)) return;
483
484 instA.dwSize = sizeof(instA);
486 ok(SUCCEEDED(hr), "got %08x\n", hr);
487
488 inst3A.dwSize = sizeof(inst3A);
490 ok(SUCCEEDED(hr), "got %08x\n", hr);
491
492 ok(instA.dwSize != inst3A.dwSize, "got %d, %d \n", instA.dwSize, inst3A.dwSize);
493 ok(IsEqualGUID(&instA.guidInstance, &inst3A.guidInstance), "got %s, %s\n",
495 ok(IsEqualGUID(&instA.guidProduct, &inst3A.guidProduct), "got %s, %s\n",
497 ok(instA.dwDevType == inst3A.dwDevType, "got %d, %d\n", instA.dwDevType, inst3A.dwDevType);
498
499 IUnknown_Release(pKey);
500}
#define IDirectInputDevice_GetDeviceInfo(p, a)
Definition: dinput.h:1616
FxRegKey * pKey
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
static __inline const char * wine_dbgstr_guid(const GUID *id)
Definition: debug.h:197
GUID guidProduct
Definition: dinput.h:414
GUID guidInstance
Definition: dinput.h:413
DWORD dwDevType
Definition: dinput.h:415

Referenced by keyboard_tests().

◆ test_set_coop()

static void test_set_coop ( IDirectInputA *  pDI,
HWND  hwnd 
)
static

Definition at line 215 of file keyboard.c.

216{
217 HRESULT hr;
218 IDirectInputDeviceA *pKeyboard = NULL;
219 int i;
220 HWND child;
221
222 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
223 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
224 if (FAILED(hr)) return;
225
226 for (i=0; i<16; i++)
227 {
229 ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %08x\n", i, hr);
230 }
231 for (i=0; i<16; i++)
232 {
233 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, (HWND)0x400000, i);
234 ok(hr == SetCoop_invalid_window[i], "SetCooperativeLevel(invalid, %d): %08x\n", i, hr);
235 }
236 for (i=0; i<16; i++)
237 {
239 ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %08x\n", i, hr);
240 }
241
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());
245
246 for (i=0; i<16; i++)
247 {
249 ok(hr == SetCoop_child_window[i], "SetCooperativeLevel(child, %d): %08x\n", i, hr);
250 }
251
253 if (pKeyboard) IUnknown_Release(pKeyboard);
254}
static const HRESULT SetCoop_invalid_window[16]
Definition: keyboard.c:197
static const HRESULT SetCoop_child_window[16]
Definition: keyboard.c:209
static const HRESULT SetCoop_null_window[16]
Definition: keyboard.c:191
static const HRESULT SetCoop_real_window[16]
Definition: keyboard.c:203
static HWND child
Definition: cursoricon.c:298
#define WS_CHILD
Definition: pedump.c:617

Referenced by keyboard_tests().

Variable Documentation

◆ DWORD

Definition at line 34 of file keyboard.c.

◆ SetCoop_child_window

const HRESULT SetCoop_child_window[16]
static

◆ SetCoop_invalid_window

◆ SetCoop_null_window

◆ SetCoop_real_window

const HRESULT SetCoop_real_window[16]
static