dinput: Reset device state in SysKeyboard*Impl_Acquire.

This commit is contained in:
Sebastian Lackner 2015-04-11 10:06:05 +02:00 committed by Alexandre Julliard
parent 4439cd433d
commit 0d91274def
2 changed files with 45 additions and 2 deletions

View File

@ -527,6 +527,29 @@ static HRESULT WINAPI SysKeyboardAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
return SysKeyboardWImpl_GetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
}
static HRESULT WINAPI SysKeyboardWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
{
SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
HRESULT res;
TRACE("(%p)\n", This);
res = IDirectInputDevice2WImpl_Acquire(iface);
if (res == DI_OK)
{
TRACE("clearing keystate\n");
memset(This->DInputKeyState, 0, sizeof(This->DInputKeyState));
}
return res;
}
static HRESULT WINAPI SysKeyboardAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
{
SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
return SysKeyboardWImpl_Acquire(IDirectInputDevice8W_from_impl(This));
}
static HRESULT WINAPI SysKeyboardWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
LPDIACTIONFORMATW lpdiaf,
LPCWSTR lpszUserName,
@ -615,7 +638,7 @@ static const IDirectInputDevice8AVtbl SysKeyboardAvt =
IDirectInputDevice2AImpl_EnumObjects,
SysKeyboardAImpl_GetProperty,
IDirectInputDevice2AImpl_SetProperty,
IDirectInputDevice2AImpl_Acquire,
SysKeyboardAImpl_Acquire,
IDirectInputDevice2AImpl_Unacquire,
SysKeyboardAImpl_GetDeviceState,
IDirectInputDevice2AImpl_GetDeviceData,
@ -651,7 +674,7 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt =
IDirectInputDevice2WImpl_EnumObjects,
SysKeyboardWImpl_GetProperty,
IDirectInputDevice2WImpl_SetProperty,
IDirectInputDevice2WImpl_Acquire,
SysKeyboardWImpl_Acquire,
IDirectInputDevice2WImpl_Unacquire,
SysKeyboardWImpl_GetDeviceState,
IDirectInputDevice2WImpl_GetDeviceData,

View File

@ -91,6 +91,26 @@ static void acquire_tests(IDirectInputA *pDI, HWND hwnd)
for (i = 0; i < sizeof(custom_state) / sizeof(custom_state[0]); i++)
ok(custom_state[i] == 0, "Should be zeroed, got 0x%08x\n", custom_state[i]);
/* simulate some keyboard input */
SetFocus(hwnd);
keybd_event('Q', 0, 0, 0);
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(custom_state), custom_state);
ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr);
if (!custom_state[0])
win_skip("Keyboard event not processed, skipping test\n");
else
{
/* unacquiring should reset the device state */
hr = IDirectInputDevice_Unacquire(pKeyboard);
ok(SUCCEEDED(hr), "IDirectInputDevice_Unacquire() failed: %08x\n", hr);
hr = IDirectInputDevice_Acquire(pKeyboard);
ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(custom_state), custom_state);
ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState failed: %08x\n", hr);
for (i = 0; i < sizeof(custom_state) / sizeof(custom_state[0]); i++)
ok(custom_state[i] == 0, "Should be zeroed, got 0x%08x\n", custom_state[i]);
}
if (pKeyboard) IUnknown_Release(pKeyboard);
}