Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/keyboard.c | 69 +++++++++++++++++++++++++++++++++---- dlls/dinput8/tests/device.c | 7 ---- 2 files changed, 62 insertions(+), 14 deletions(-)
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index b5e665933ec..44f82bee9a6 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -107,17 +107,65 @@ static int KeyboardCallback( LPDIRECTINPUTDEVICE8A iface, WPARAM wparam, LPARAM { SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface); int dik_code, ret = This->base.dwCoopLevel & DISCL_EXCLUSIVE; - KBDLLHOOKSTRUCT *hook = (KBDLLHOOKSTRUCT *)lparam; BYTE new_diks; + DWORD vkey_code, scan_code; + BOOL is_key_ext, is_key_up;
if (wparam != WM_KEYDOWN && wparam != WM_KEYUP && - wparam != WM_SYSKEYDOWN && wparam != WM_SYSKEYUP) + wparam != WM_SYSKEYDOWN && wparam != WM_SYSKEYUP && + wparam != RIM_INPUT && wparam != RIM_INPUTSINK) return 0;
+ if (wparam == RIM_INPUT || wparam == RIM_INPUTSINK) + { + RAWINPUTHEADER raw_header; + RAWINPUT raw_input; + UINT size; + + TRACE("(%p) wp %08lx, lp %08lx\n", iface, wparam, lparam); + + size = sizeof(raw_header); + if (GetRawInputData( (HRAWINPUT)lparam, RID_HEADER, &raw_header, &size, sizeof(RAWINPUTHEADER) ) != sizeof(raw_header)) + { + WARN( "Unable to read raw input data header\n" ); + return 0; + } + + if (raw_header.dwType != RIM_TYPEKEYBOARD) + return 0; + + if (raw_header.dwSize > sizeof(raw_input)) + { + WARN( "Unexpected size for keyboard raw input data\n" ); + return 0; + } + + size = raw_header.dwSize; + if (GetRawInputData( (HRAWINPUT)lparam, RID_INPUT, &raw_input, &size, sizeof(RAWINPUTHEADER) ) != raw_header.dwSize ) + { + WARN( "Unable to read raw input data\n" ); + return 0; + } + + vkey_code = raw_input.data.keyboard.VKey; + scan_code = raw_input.data.keyboard.MakeCode; + is_key_ext = (raw_input.data.keyboard.Flags & RI_KEY_E0); + is_key_up = (raw_input.data.keyboard.Flags & RI_KEY_BREAK); + } + else + { + KBDLLHOOKSTRUCT *hook = (KBDLLHOOKSTRUCT *)lparam; + + vkey_code = hook->vkCode; + scan_code = hook->scanCode; + is_key_ext = (hook->flags & LLKHF_EXTENDED); + is_key_up = (hook->flags & LLKHF_UP); + } + TRACE("(%p) wp %08lx, lp %08lx, vk %02x, scan %02x\n", - iface, wparam, lparam, hook->vkCode, hook->scanCode); + iface, wparam, lparam, vkey_code, scan_code);
- switch (hook->vkCode) + switch (vkey_code) { /* R-Shift is special - it is an extended key with separate scan code */ case VK_RSHIFT : dik_code = DIK_RSHIFT; break; @@ -125,10 +173,10 @@ static int KeyboardCallback( LPDIRECTINPUTDEVICE8A iface, WPARAM wparam, LPARAM case VK_NUMLOCK : dik_code = DIK_NUMLOCK; break; case VK_SUBTRACT: dik_code = DIK_SUBTRACT; break; default: - dik_code = map_dik_code(hook->scanCode & 0xff, hook->vkCode, This->subtype); - if (hook->flags & LLKHF_EXTENDED) dik_code |= 0x80; + dik_code = map_dik_code(scan_code & 0xff, vkey_code, This->subtype); + if (is_key_ext) dik_code |= 0x80; } - new_diks = hook->flags & LLKHF_UP ? 0 : 0x80; + new_diks = is_key_up ? 0 : 0x80;
/* returns now if key event already known */ if (new_diks == This->DInputKeyState[dik_code]) @@ -295,6 +343,13 @@ static SysKeyboardImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput) list_add_tail(&dinput->devices_list, &newDevice->base.entry); LeaveCriticalSection(&dinput->crit);
+ if (dinput->dwVersion >= 0x800) + { + newDevice->base.use_raw_input = TRUE; + newDevice->base.raw_device.usUsagePage = 1; /* HID generic device page */ + newDevice->base.raw_device.usUsage = 6; /* HID generic keyboard */ + } + return newDevice;
failed: diff --git a/dlls/dinput8/tests/device.c b/dlls/dinput8/tests/device.c index 2b7814e3bbc..9f2d0dbd29a 100644 --- a/dlls/dinput8/tests/device.c +++ b/dlls/dinput8/tests/device.c @@ -609,15 +609,10 @@ static void test_mouse_keyboard(void) raw_devices_count = ARRAY_SIZE(raw_devices); memset(raw_devices, 0, sizeof(raw_devices)); hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE)); - todo_wine ok(hr == 1, "GetRegisteredRawInputDevices returned %d, raw_devices_count: %d\n", hr, raw_devices_count); - todo_wine ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage); - todo_wine ok(raw_devices[0].usUsage == 6, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage); - todo_wine ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %x\n", raw_devices[0].dwFlags); - todo_wine ok(raw_devices[0].hwndTarget != NULL, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget); hr = IDirectInputDevice8_Unacquire(di_keyboard); ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr); @@ -699,9 +694,7 @@ static void test_mouse_keyboard(void) ok(raw_devices[1].hwndTarget == hwnd, "Unexpected raw device target: %p\n", raw_devices[1].hwndTarget); ok(raw_devices[2].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[1].usUsagePage); ok(raw_devices[2].usUsage == 6, "Unexpected raw device usage: %x\n", raw_devices[1].usUsage); - todo_wine ok(raw_devices[2].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %x\n", raw_devices[1].dwFlags); - todo_wine ok(raw_devices[2].hwndTarget == di_hwnd, "Unexpected raw device target: %p\n", raw_devices[1].hwndTarget); hr = IDirectInputDevice8_Unacquire(di_keyboard); ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);