Commit aa7a6b8f authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dinput: Use rawinput interface for keyboard device.

parent a75e0d06
......@@ -200,6 +200,7 @@ static LRESULT CALLBACK cbt_hook_proc( int code, WPARAM wparam, LPARAM lparam )
static void input_thread_update_device_list( struct input_thread_state *state )
{
RAWINPUTDEVICE rawinput_keyboard = {.usUsagePage = HID_USAGE_PAGE_GENERIC, .usUsage = HID_USAGE_GENERIC_KEYBOARD, .dwFlags = RIDEV_REMOVE};
RAWINPUTDEVICE rawinput_mouse = {.usUsagePage = HID_USAGE_PAGE_GENERIC, .usUsage = HID_USAGE_GENERIC_MOUSE, .dwFlags = RIDEV_REMOVE};
UINT count = 0, keyboard_ll_count = 0, mouse_ll_count = 0, foreground_count = 0;
struct dinput_device *device;
......@@ -230,7 +231,9 @@ static void input_thread_update_device_list( struct input_thread_state *state )
break;
case DIDEVTYPE_KEYBOARD:
case DI8DEVTYPE_KEYBOARD:
if (device->dwCoopLevel & DISCL_EXCLUSIVE) rawinput_keyboard.dwFlags |= RIDEV_NOHOTKEYS;
if (!device->use_raw_input) keyboard_ll_count++;
else rawinput_device = &rawinput_keyboard;
break;
}
......@@ -274,8 +277,12 @@ static void input_thread_update_device_list( struct input_thread_state *state )
if (!rawinput_mouse.hwndTarget != !state->rawinput_devices[0].hwndTarget &&
!RegisterRawInputDevices( &rawinput_mouse, 1, sizeof(RAWINPUTDEVICE) ))
WARN( "Failed to (un)register rawinput mouse device.\n" );
if (!rawinput_keyboard.hwndTarget != !state->rawinput_devices[1].hwndTarget &&
!RegisterRawInputDevices( &rawinput_keyboard, 1, sizeof(RAWINPUTDEVICE) ))
WARN( "Failed to (un)register rawinput mouse device.\n" );
state->rawinput_devices[0] = rawinput_mouse;
state->rawinput_devices[1] = rawinput_keyboard;
}
static LRESULT WINAPI di_em_win_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
......@@ -292,7 +299,9 @@ static LRESULT WINAPI di_em_win_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPAR
size = GetRawInputData( (HRAWINPUT)lparam, RID_INPUT, &ri, &size, sizeof(RAWINPUTHEADER) );
if (size == (UINT)-1 || size < sizeof(RAWINPUTHEADER))
WARN( "Unable to read raw input data\n" );
else if (ri.header.dwType == RIM_TYPEMOUSE)
else if (ri.header.dwType == RIM_TYPEHID)
WARN( "Unexpected HID rawinput message\n" );
else
{
for (i = state->events_count; i < state->devices_count; ++i)
{
......@@ -303,8 +312,14 @@ static LRESULT WINAPI di_em_win_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPAR
{
case DIDEVTYPE_MOUSE:
case DI8DEVTYPE_MOUSE:
if (ri.header.dwType != RIM_TYPEMOUSE) break;
dinput_mouse_rawinput_hook( &device->IDirectInputDevice8W_iface, wparam, lparam, &ri );
break;
case DIDEVTYPE_KEYBOARD:
case DI8DEVTYPE_KEYBOARD:
if (ri.header.dwType != RIM_TYPEKEYBOARD) break;
dinput_keyboard_rawinput_hook( &device->IDirectInputDevice8W_iface, wparam, lparam, &ri );
break;
default: break;
}
}
......
......@@ -72,6 +72,8 @@ extern int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM
extern int dinput_keyboard_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam );
extern void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam,
RAWINPUT *raw );
extern void dinput_keyboard_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam,
RAWINPUT *raw );
extern void check_dinput_events(void) DECLSPEC_HIDDEN;
......
......@@ -115,6 +115,18 @@ static void keyboard_handle_event( struct keyboard *impl, DWORD vkey, DWORD scan
LeaveCriticalSection( &impl->base.crit );
}
void dinput_keyboard_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam, RAWINPUT *ri )
{
struct keyboard *impl = impl_from_IDirectInputDevice8W( iface );
DWORD scan_code;
TRACE("(%p) wparam %Ix, lparam %Ix\n", iface, wparam, lparam);
scan_code = ri->data.keyboard.MakeCode & 0xff;
if (ri->data.keyboard.Flags & RI_KEY_E0) scan_code |= 0x100;
keyboard_handle_event( impl, ri->data.keyboard.VKey, scan_code, ri->data.keyboard.Flags & RI_KEY_BREAK );
}
int dinput_keyboard_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam )
{
struct keyboard *impl = impl_from_IDirectInputDevice8W( iface );
......@@ -189,6 +201,9 @@ HRESULT keyboard_create_device( struct dinput *dinput, const GUID *guid, IDirect
impl->base.caps.dwFirmwareRevision = 100;
impl->base.caps.dwHardwareRevision = 100;
if (dinput->dwVersion >= 0x0800)
impl->base.use_raw_input = TRUE;
*out = &impl->base.IDirectInputDevice8W_iface;
return DI_OK;
}
......
......@@ -1099,15 +1099,11 @@ 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 %ld, raw_devices_count: %d\n", hr, raw_devices_count);
todo_wine
ok(raw_devices[0].usUsagePage == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[0].usUsagePage);
todo_wine
ok(raw_devices[0].usUsage == HID_USAGE_GENERIC_KEYBOARD, "got usUsage: %x\n", raw_devices[0].usUsage);
todo_wine
ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %#lx\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: %#lx\n", hr);
......@@ -1139,7 +1135,6 @@ static void test_mouse_keyboard(void)
ok(raw_devices[0].usUsagePage == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[0].usUsagePage);
ok(raw_devices[0].usUsage == HID_USAGE_GENERIC_MOUSE, "got usUsage: %x\n", raw_devices[0].usUsage);
ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %#lx\n", raw_devices[0].dwFlags);
todo_wine
ok(raw_devices[0].hwndTarget == di_hwnd, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget);
hr = IDirectInputDevice8_Unacquire(di_mouse);
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %#lx\n", hr);
......@@ -1185,9 +1180,6 @@ 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 == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[1].usUsagePage);
ok(raw_devices[2].usUsage == HID_USAGE_GENERIC_KEYBOARD, "got usUsage: %x\n", raw_devices[1].usUsage);
todo_wine
ok(raw_devices[2].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %#lx\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: %#lx\n", hr);
......@@ -1195,7 +1187,6 @@ static void test_mouse_keyboard(void)
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %#lx\n", hr);
raw_devices_count = ARRAY_SIZE(raw_devices);
GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE));
todo_wine
ok(raw_devices_count == 1, "Unexpected raw devices registered: %d\n", raw_devices_count);
IDirectInputDevice8_SetCooperativeLevel(di_mouse, hwnd, DISCL_FOREGROUND|DISCL_EXCLUSIVE);
......@@ -1210,7 +1201,6 @@ static void test_mouse_keyboard(void)
hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE));
ok(hr == 3, "GetRegisteredRawInputDevices returned %ld, raw_devices_count: %d\n", hr, raw_devices_count);
ok(raw_devices[0].dwFlags == (RIDEV_CAPTUREMOUSE|RIDEV_NOLEGACY), "Unexpected raw device flags: %#lx\n", raw_devices[0].dwFlags);
todo_wine
ok(raw_devices[2].dwFlags == (RIDEV_NOHOTKEYS|RIDEV_NOLEGACY), "Unexpected raw device flags: %#lx\n", raw_devices[1].dwFlags);
hr = IDirectInputDevice8_Unacquire(di_keyboard);
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %#lx\n", hr);
......@@ -1219,7 +1209,6 @@ static void test_mouse_keyboard(void)
raw_devices_count = ARRAY_SIZE(raw_devices);
hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE));
todo_wine
ok(hr == 1, "GetRegisteredRawInputDevices returned %ld, raw_devices_count: %d\n", hr, raw_devices_count);
ok(raw_devices[0].usUsagePage == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[0].usUsagePage);
ok(raw_devices[0].usUsage == HID_USAGE_GENERIC_GAMEPAD, "got usUsage: %x\n", raw_devices[0].usUsage);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment