2011-04-30 00:29:19 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 Lucas Fialho Zawacki
|
|
|
|
* Copyright (c) 2006 Vitaliy Margolen
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DIRECTINPUT_VERSION 0x0800
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "dinput.h"
|
|
|
|
|
2011-06-28 18:54:20 +02:00
|
|
|
struct enum_data {
|
2013-11-08 20:49:48 +01:00
|
|
|
IDirectInput8A *pDI;
|
|
|
|
DIACTIONFORMATA *lpdiaf;
|
|
|
|
IDirectInputDevice8A *keyboard;
|
|
|
|
IDirectInputDevice8A *mouse;
|
2011-10-22 22:53:21 +02:00
|
|
|
const char* username;
|
2011-06-28 18:54:20 +02:00
|
|
|
int ndevices;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Dummy GUID */
|
|
|
|
static const GUID ACTION_MAPPING_GUID = { 0x1, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } };
|
|
|
|
|
2011-06-28 18:54:49 +02:00
|
|
|
enum {
|
|
|
|
DITEST_AXIS,
|
|
|
|
DITEST_BUTTON,
|
|
|
|
DITEST_KEYBOARDSPACE,
|
|
|
|
DITEST_MOUSEBUTTON0,
|
2011-07-02 06:06:01 +02:00
|
|
|
DITEST_YAXIS
|
2011-06-28 18:54:49 +02:00
|
|
|
};
|
|
|
|
|
2013-11-08 20:49:48 +01:00
|
|
|
static DIACTIONA actionMapping[]=
|
2011-06-28 18:54:20 +02:00
|
|
|
{
|
|
|
|
/* axis */
|
2016-08-05 00:50:51 +02:00
|
|
|
{ 0, 0x01008A01 /* DIAXIS_DRIVINGR_STEER */, 0, { "Steer.\0" } },
|
2011-06-28 18:54:20 +02:00
|
|
|
/* button */
|
2016-08-05 00:50:51 +02:00
|
|
|
{ 1, 0x01000C01 /* DIBUTTON_DRIVINGR_SHIFTUP */, 0, { "Upshift.\0" } },
|
2011-06-28 18:54:20 +02:00
|
|
|
/* keyboard key */
|
2016-08-05 00:50:51 +02:00
|
|
|
{ 2, DIKEYBOARD_SPACE, 0, { "Missile.\0" } },
|
2011-06-28 18:54:20 +02:00
|
|
|
/* mouse button */
|
2016-08-05 00:50:51 +02:00
|
|
|
{ 3, DIMOUSE_BUTTON0, 0, { "Select\0" } },
|
2011-07-02 06:06:01 +02:00
|
|
|
/* mouse axis */
|
2016-08-05 00:50:51 +02:00
|
|
|
{ 4, DIMOUSE_YAXIS, 0, { "Y Axis\0" } }
|
2011-06-28 18:54:20 +02:00
|
|
|
};
|
2016-08-05 00:50:51 +02:00
|
|
|
/* By placing the memory pointed to by lptszActionName right before memory with PAGE_NOACCESS
|
|
|
|
* one can find out that the regular ansi string termination is not respected by EnumDevicesBySemantics.
|
|
|
|
* Adding a double termination, making it a valid wide string termination, made the test succeed.
|
|
|
|
* Therefore it looks like ansi version of EnumDevicesBySemantics forwards the string to
|
|
|
|
* the wide variant without conversation. */
|
2011-06-28 18:54:20 +02:00
|
|
|
|
2014-03-07 01:49:58 +01:00
|
|
|
static void flush_events(void)
|
|
|
|
{
|
|
|
|
int diff = 200;
|
|
|
|
int min_timeout = 100;
|
|
|
|
DWORD time = GetTickCount() + diff;
|
|
|
|
|
|
|
|
while (diff > 0)
|
|
|
|
{
|
|
|
|
if (MsgWaitForMultipleObjects(0, NULL, FALSE, min_timeout, QS_ALLINPUT) == WAIT_TIMEOUT)
|
|
|
|
break;
|
|
|
|
diff = time - GetTickCount();
|
|
|
|
min_timeout = 50;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-08 13:36:08 +01:00
|
|
|
static void test_device_input(IDirectInputDevice8A *lpdid, DWORD event_type, DWORD event, UINT_PTR expected)
|
2011-06-28 18:54:49 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DIDEVICEOBJECTDATA obj_data;
|
|
|
|
DWORD data_size = 1;
|
2011-10-16 20:36:50 +02:00
|
|
|
int i;
|
2011-06-28 18:54:49 +02:00
|
|
|
|
|
|
|
hr = IDirectInputDevice8_Acquire(lpdid);
|
2011-07-02 06:06:54 +02:00
|
|
|
ok (SUCCEEDED(hr), "Failed to acquire device hr=%08x\n", hr);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
2011-07-02 06:06:01 +02:00
|
|
|
if (event_type == INPUT_KEYBOARD)
|
2021-05-26 13:10:58 +02:00
|
|
|
keybd_event(0, event, KEYEVENTF_SCANCODE, 0);
|
2011-07-02 06:06:01 +02:00
|
|
|
|
|
|
|
if (event_type == INPUT_MOUSE)
|
|
|
|
mouse_event( event, 0, 0, 0, 0);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
2014-03-07 01:49:58 +01:00
|
|
|
flush_events();
|
2011-06-28 18:54:49 +02:00
|
|
|
IDirectInputDevice8_Poll(lpdid);
|
|
|
|
hr = IDirectInputDevice8_GetDeviceData(lpdid, sizeof(obj_data), &obj_data, &data_size, 0);
|
|
|
|
|
|
|
|
if (data_size != 1)
|
|
|
|
{
|
|
|
|
win_skip("We're not able to inject input into Windows dinput8 with events\n");
|
2014-03-07 01:49:58 +01:00
|
|
|
IDirectInputDevice_Unacquire(lpdid);
|
2011-06-28 18:54:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-08 13:36:08 +01:00
|
|
|
ok (obj_data.uAppData == expected, "Retrieval of action failed uAppData=%lu expected=%lu\n", obj_data.uAppData, expected);
|
2011-10-16 20:36:50 +02:00
|
|
|
|
2019-09-08 06:19:53 +02:00
|
|
|
/* Check for buffer overflow */
|
2011-10-16 20:36:50 +02:00
|
|
|
for (i = 0; i < 17; i++)
|
|
|
|
if (event_type == INPUT_KEYBOARD)
|
|
|
|
{
|
|
|
|
keybd_event( VK_SPACE, DIK_SPACE, 0, 0);
|
|
|
|
keybd_event( VK_SPACE, DIK_SPACE, KEYEVENTF_KEYUP, 0);
|
|
|
|
}
|
|
|
|
else if (event_type == INPUT_MOUSE)
|
|
|
|
{
|
|
|
|
mouse_event(MOUSEEVENTF_LEFTDOWN, 1, 1, 0, 0);
|
|
|
|
mouse_event(MOUSEEVENTF_LEFTUP, 1, 1, 0, 0);
|
|
|
|
}
|
|
|
|
|
2014-03-07 01:49:58 +01:00
|
|
|
flush_events();
|
2011-10-16 20:36:50 +02:00
|
|
|
IDirectInputDevice8_Poll(lpdid);
|
|
|
|
|
|
|
|
data_size = 1;
|
|
|
|
hr = IDirectInputDevice8_GetDeviceData(lpdid, sizeof(obj_data), &obj_data, &data_size, 0);
|
|
|
|
ok(hr == DI_BUFFEROVERFLOW, "GetDeviceData() failed: %08x\n", hr);
|
|
|
|
data_size = 1;
|
|
|
|
hr = IDirectInputDevice8_GetDeviceData(lpdid, sizeof(obj_data), &obj_data, &data_size, 0);
|
|
|
|
ok(hr == DI_OK && data_size == 1, "GetDeviceData() failed: %08x cnt:%d\n", hr, data_size);
|
2014-03-07 01:49:58 +01:00
|
|
|
|
2021-03-08 13:36:08 +01:00
|
|
|
/* drain device's queue */
|
|
|
|
while (data_size == 1)
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice8_GetDeviceData(lpdid, sizeof(obj_data), &obj_data, &data_size, 0);
|
|
|
|
ok(hr == DI_OK, "GetDeviceData() failed: %08x cnt:%d\n", hr, data_size);
|
|
|
|
if (hr != DI_OK) break;
|
|
|
|
}
|
|
|
|
|
2014-03-07 01:49:58 +01:00
|
|
|
IDirectInputDevice_Unacquire(lpdid);
|
2011-06-28 18:54:49 +02:00
|
|
|
}
|
|
|
|
|
2013-11-08 20:49:48 +01:00
|
|
|
static void test_build_action_map(IDirectInputDevice8A *lpdid, DIACTIONFORMATA *lpdiaf,
|
|
|
|
int action_index, DWORD expected_type, DWORD expected_inst)
|
2011-06-28 18:54:49 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2013-11-08 20:49:48 +01:00
|
|
|
DIACTIONA *actions;
|
2011-07-02 06:06:01 +02:00
|
|
|
DWORD instance, type, how;
|
2011-06-28 18:54:49 +02:00
|
|
|
GUID assigned_to;
|
|
|
|
DIDEVICEINSTANCEA ddi;
|
|
|
|
|
|
|
|
ddi.dwSize = sizeof(ddi);
|
|
|
|
IDirectInputDevice_GetDeviceInfo(lpdid, &ddi);
|
|
|
|
|
2012-08-24 19:04:51 +02:00
|
|
|
hr = IDirectInputDevice8_BuildActionMap(lpdid, lpdiaf, NULL, DIDBAM_HWDEFAULTS);
|
2011-06-28 18:54:49 +02:00
|
|
|
ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
|
|
|
|
|
|
|
|
actions = lpdiaf->rgoAction;
|
2011-07-02 06:06:01 +02:00
|
|
|
instance = DIDFT_GETINSTANCE(actions[action_index].dwObjID);
|
|
|
|
type = DIDFT_GETTYPE(actions[action_index].dwObjID);
|
2011-06-28 18:54:49 +02:00
|
|
|
how = actions[action_index].dwHow;
|
|
|
|
assigned_to = actions[action_index].guidInstance;
|
|
|
|
|
2011-07-02 06:06:37 +02:00
|
|
|
ok (how == DIAH_USERCONFIG || how == DIAH_DEFAULT, "Action was not set dwHow=%08x\n", how);
|
|
|
|
ok (instance == expected_inst, "Action not mapped correctly instance=%08x expected=%08x\n", instance, expected_inst);
|
|
|
|
ok (type == expected_type, "Action type not mapped correctly type=%08x expected=%08x\n", type, expected_type);
|
|
|
|
ok (IsEqualGUID(&assigned_to, &ddi.guidInstance), "Action and device GUID do not match action=%d\n", action_index);
|
2011-06-28 18:54:49 +02:00
|
|
|
}
|
|
|
|
|
2013-11-08 20:49:48 +01:00
|
|
|
static BOOL CALLBACK enumeration_callback(const DIDEVICEINSTANCEA *lpddi, IDirectInputDevice8A *lpdid,
|
|
|
|
DWORD dwFlags, DWORD dwRemaining, LPVOID pvRef)
|
2011-04-30 00:29:19 +02:00
|
|
|
{
|
2011-06-28 18:54:49 +02:00
|
|
|
HRESULT hr;
|
|
|
|
DIPROPDWORD dp;
|
2011-07-21 20:37:15 +02:00
|
|
|
DIPROPRANGE dpr;
|
2011-10-22 22:53:21 +02:00
|
|
|
DIPROPSTRING dps;
|
|
|
|
WCHAR usernameW[MAX_PATH];
|
|
|
|
DWORD username_size = MAX_PATH;
|
2011-06-28 18:54:20 +02:00
|
|
|
struct enum_data *data = pvRef;
|
2011-10-16 20:36:50 +02:00
|
|
|
DWORD cnt;
|
|
|
|
DIDEVICEOBJECTDATA buffer[5];
|
2017-03-02 19:51:40 +01:00
|
|
|
IDirectInputDevice8A *lpdid2;
|
2011-10-16 20:36:50 +02:00
|
|
|
|
2011-06-28 18:54:20 +02:00
|
|
|
if (!data) return DIENUM_CONTINUE;
|
|
|
|
|
|
|
|
data->ndevices++;
|
|
|
|
|
2011-10-22 22:53:21 +02:00
|
|
|
/* Convert username to WCHAR */
|
|
|
|
if (data->username != NULL)
|
|
|
|
{
|
|
|
|
username_size = MultiByteToWideChar(CP_ACP, 0, data->username, -1, usernameW, 0);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, data->username, -1, usernameW, username_size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
GetUserNameW(usernameW, &username_size);
|
|
|
|
|
2011-06-28 18:54:20 +02:00
|
|
|
/* collect the mouse and keyboard */
|
|
|
|
if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysKeyboard))
|
|
|
|
{
|
|
|
|
IDirectInputDevice_AddRef(lpdid);
|
|
|
|
data->keyboard = lpdid;
|
|
|
|
|
2011-06-28 18:54:36 +02:00
|
|
|
ok (dwFlags & DIEDBS_MAPPEDPRI1, "Keyboard should be mapped as pri1 dwFlags=%08x\n", dwFlags);
|
2011-06-28 18:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysMouse))
|
|
|
|
{
|
|
|
|
IDirectInputDevice_AddRef(lpdid);
|
|
|
|
data->mouse = lpdid;
|
|
|
|
|
2011-06-28 18:54:36 +02:00
|
|
|
ok (dwFlags & DIEDBS_MAPPEDPRI1, "Mouse should be mapped as pri1 dwFlags=%08x\n", dwFlags);
|
2011-06-28 18:54:20 +02:00
|
|
|
}
|
|
|
|
|
2017-03-02 19:51:40 +01:00
|
|
|
/* Creating second device object to check if it has the same username */
|
|
|
|
hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance, &lpdid2, NULL);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
|
|
|
|
|
2011-06-28 18:54:49 +02:00
|
|
|
/* Building and setting an action map */
|
2012-08-24 19:04:51 +02:00
|
|
|
/* It should not use any pre-stored mappings so we use DIDBAM_HWDEFAULTS */
|
|
|
|
hr = IDirectInputDevice8_BuildActionMap(lpdid, data->lpdiaf, NULL, DIDBAM_HWDEFAULTS);
|
2011-06-28 18:54:49 +02:00
|
|
|
ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
|
|
|
|
|
|
|
|
/* Device has no data format and thus can't be acquired */
|
|
|
|
hr = IDirectInputDevice8_Acquire(lpdid);
|
|
|
|
ok (hr == DIERR_INVALIDPARAM, "Device was acquired before SetActionMap hr=%08x\n", hr);
|
|
|
|
|
2011-10-22 22:53:21 +02:00
|
|
|
hr = IDirectInputDevice8_SetActionMap(lpdid, data->lpdiaf, data->username, 0);
|
2011-06-28 18:54:49 +02:00
|
|
|
ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
|
|
|
|
|
2011-07-12 03:37:36 +02:00
|
|
|
/* Some joysticks may have no suitable actions and thus should not be tested */
|
|
|
|
if (hr == DI_NOEFFECT) return DIENUM_CONTINUE;
|
|
|
|
|
2011-10-22 22:53:21 +02:00
|
|
|
/* Test username after SetActionMap */
|
|
|
|
dps.diph.dwSize = sizeof(dps);
|
|
|
|
dps.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
dps.diph.dwObj = 0;
|
|
|
|
dps.diph.dwHow = DIPH_DEVICE;
|
|
|
|
dps.wsz[0] = '\0';
|
|
|
|
|
|
|
|
hr = IDirectInputDevice_GetProperty(lpdid, DIPROP_USERNAME, &dps.diph);
|
2016-03-31 05:39:21 +02:00
|
|
|
ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr);
|
|
|
|
ok (!lstrcmpW(usernameW, dps.wsz), "Username not set correctly expected=%s, got=%s\n", wine_dbgstr_w(usernameW), wine_dbgstr_w(dps.wsz));
|
2011-10-22 22:53:21 +02:00
|
|
|
|
2017-03-02 19:51:40 +01:00
|
|
|
dps.wsz[0] = '\0';
|
|
|
|
hr = IDirectInputDevice_GetProperty(lpdid2, DIPROP_USERNAME, &dps.diph);
|
|
|
|
ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr);
|
|
|
|
ok (!lstrcmpW(usernameW, dps.wsz), "Username not set correctly expected=%s, got=%s\n", wine_dbgstr_w(usernameW), wine_dbgstr_w(dps.wsz));
|
|
|
|
|
2011-06-28 18:54:49 +02:00
|
|
|
/* Test buffer size */
|
|
|
|
memset(&dp, 0, sizeof(dp));
|
|
|
|
dp.diph.dwSize = sizeof(dp);
|
|
|
|
dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
dp.diph.dwHow = DIPH_DEVICE;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice_GetProperty(lpdid, DIPROP_BUFFERSIZE, &dp.diph);
|
|
|
|
ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr);
|
2011-06-28 18:55:24 +02:00
|
|
|
ok (dp.dwData == data->lpdiaf->dwBufferSize, "SetActionMap must set the buffer, buffersize=%d\n", dp.dwData);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
2011-10-16 20:36:50 +02:00
|
|
|
cnt = 1;
|
|
|
|
hr = IDirectInputDevice_GetDeviceData(lpdid, sizeof(buffer[0]), buffer, &cnt, 0);
|
|
|
|
ok(hr == DIERR_NOTACQUIRED, "GetDeviceData() failed hr=%08x\n", hr);
|
|
|
|
|
2011-07-21 20:37:15 +02:00
|
|
|
/* Test axis range */
|
|
|
|
memset(&dpr, 0, sizeof(dpr));
|
|
|
|
dpr.diph.dwSize = sizeof(dpr);
|
|
|
|
dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
dpr.diph.dwHow = DIPH_DEVICE;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice_GetProperty(lpdid, DIPROP_RANGE, &dpr.diph);
|
|
|
|
/* Only test if device supports the range property */
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
ok (dpr.lMin == data->lpdiaf->lAxisMin, "SetActionMap must set the min axis range expected=%d got=%d\n", data->lpdiaf->lAxisMin, dpr.lMin);
|
|
|
|
ok (dpr.lMax == data->lpdiaf->lAxisMax, "SetActionMap must set the max axis range expected=%d got=%d\n", data->lpdiaf->lAxisMax, dpr.lMax);
|
|
|
|
}
|
|
|
|
|
2011-06-28 18:54:49 +02:00
|
|
|
/* SetActionMap has set the data format so now it should work */
|
|
|
|
hr = IDirectInputDevice8_Acquire(lpdid);
|
2011-07-02 06:06:54 +02:00
|
|
|
ok (SUCCEEDED(hr), "Acquire failed hr=%08x\n", hr);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
2011-10-16 20:36:50 +02:00
|
|
|
cnt = 1;
|
|
|
|
hr = IDirectInputDevice_GetDeviceData(lpdid, sizeof(buffer[0]), buffer, &cnt, 0);
|
|
|
|
ok(hr == DI_OK, "GetDeviceData() failed hr=%08x\n", hr);
|
|
|
|
|
2011-06-28 18:54:49 +02:00
|
|
|
/* SetActionMap should not work on an acquired device */
|
|
|
|
hr = IDirectInputDevice8_SetActionMap(lpdid, data->lpdiaf, NULL, 0);
|
2011-07-02 06:06:54 +02:00
|
|
|
ok (hr == DIERR_ACQUIRED, "SetActionMap succeeded with an acquired device hr=%08x\n", hr);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
2019-02-21 14:54:15 +01:00
|
|
|
IDirectInputDevice_Release(lpdid2);
|
|
|
|
|
2011-04-30 00:29:19 +02:00
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2021-03-08 13:36:11 +01:00
|
|
|
static void test_appdata_property_vs_map(struct enum_data *data)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DIPROPPOINTER dp;
|
|
|
|
|
|
|
|
dp.diph.dwSize = sizeof(dp);
|
|
|
|
dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
dp.diph.dwHow = DIPH_BYID;
|
|
|
|
dp.diph.dwObj = DIDFT_MAKEINSTANCE(DIK_SPACE) | DIDFT_PSHBUTTON;
|
|
|
|
dp.uData = 10;
|
|
|
|
hr = IDirectInputDevice8_SetProperty(data->keyboard, DIPROP_APPDATA, &(dp.diph));
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_SetProperty failed hr=%08x\n", hr);
|
|
|
|
|
2021-05-26 13:10:58 +02:00
|
|
|
test_device_input(data->keyboard, INPUT_KEYBOARD, DIK_SPACE, 10);
|
2021-03-08 13:36:11 +01:00
|
|
|
|
|
|
|
dp.diph.dwHow = DIPH_BYID;
|
|
|
|
dp.diph.dwObj = DIDFT_MAKEINSTANCE(DIK_V) | DIDFT_PSHBUTTON;
|
|
|
|
dp.uData = 11;
|
|
|
|
hr = IDirectInputDevice8_SetProperty(data->keyboard, DIPROP_APPDATA, &(dp.diph));
|
|
|
|
ok(hr == DIERR_OBJECTNOTFOUND, "IDirectInputDevice8_SetProperty should not find key that's not in the action map hr=%08x\n", hr);
|
|
|
|
|
|
|
|
/* setting format should reset action map */
|
|
|
|
hr = IDirectInputDevice8_SetDataFormat(data->keyboard, &c_dfDIKeyboard);
|
|
|
|
ok(SUCCEEDED(hr), "SetDataFormat failed: %08x\n", hr);
|
|
|
|
|
2021-05-26 13:10:58 +02:00
|
|
|
test_device_input(data->keyboard, INPUT_KEYBOARD, DIK_SPACE, -1);
|
2021-03-08 13:36:11 +01:00
|
|
|
|
|
|
|
dp.diph.dwHow = DIPH_BYID;
|
|
|
|
dp.diph.dwObj = DIDFT_MAKEINSTANCE(DIK_V) | DIDFT_PSHBUTTON;
|
|
|
|
dp.uData = 11;
|
|
|
|
hr = IDirectInputDevice8_SetProperty(data->keyboard, DIPROP_APPDATA, &(dp.diph));
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_SetProperty failed hr=%08x\n", hr);
|
|
|
|
|
2021-05-26 13:10:58 +02:00
|
|
|
test_device_input(data->keyboard, INPUT_KEYBOARD, DIK_V, 11);
|
2021-03-08 13:36:11 +01:00
|
|
|
|
|
|
|
/* back to action map */
|
|
|
|
hr = IDirectInputDevice8_SetActionMap(data->keyboard, data->lpdiaf, NULL, 0);
|
|
|
|
ok(SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
|
|
|
|
|
2021-05-26 13:10:58 +02:00
|
|
|
test_device_input(data->keyboard, INPUT_KEYBOARD, DIK_SPACE, 2);
|
2021-03-08 13:36:11 +01:00
|
|
|
}
|
|
|
|
|
2011-04-30 00:29:19 +02:00
|
|
|
static void test_action_mapping(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2013-11-08 20:49:48 +01:00
|
|
|
HINSTANCE hinst = GetModuleHandleA(NULL);
|
|
|
|
IDirectInput8A *pDI = NULL;
|
|
|
|
DIACTIONFORMATA af;
|
2016-03-31 05:39:21 +02:00
|
|
|
DIPROPSTRING dps;
|
2011-10-22 22:53:21 +02:00
|
|
|
struct enum_data data = {pDI, &af, NULL, NULL, NULL, 0};
|
2014-03-07 01:49:58 +01:00
|
|
|
HWND hwnd;
|
2011-04-30 00:29:19 +02:00
|
|
|
|
2012-03-25 15:48:37 +02:00
|
|
|
hr = CoCreateInstance(&CLSID_DirectInput8, 0, CLSCTX_INPROC_SERVER, &IID_IDirectInput8A, (LPVOID*)&pDI);
|
2011-04-30 00:29:19 +02:00
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION ||
|
|
|
|
hr == DIERR_BETADIRECTINPUTVERSION ||
|
|
|
|
hr == REGDB_E_CLASSNOTREG)
|
|
|
|
{
|
|
|
|
win_skip("ActionMapping requires dinput8\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(SUCCEEDED(hr), "DirectInput8 Create failed: hr=%08x\n", hr);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IDirectInput8_Initialize(pDI,hinst, DIRECTINPUT_VERSION);
|
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_BETADIRECTINPUTVERSION)
|
|
|
|
{
|
|
|
|
win_skip("ActionMapping requires dinput8\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(SUCCEEDED(hr), "DirectInput8 Initialize failed: hr=%08x\n", hr);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
memset (&af, 0, sizeof(af));
|
|
|
|
af.dwSize = sizeof(af);
|
2013-11-08 20:49:48 +01:00
|
|
|
af.dwActionSize = sizeof(DIACTIONA);
|
2018-06-07 23:44:38 +02:00
|
|
|
af.dwDataSize = 4 * ARRAY_SIZE(actionMapping);
|
|
|
|
af.dwNumActions = ARRAY_SIZE(actionMapping);
|
2011-04-30 00:29:19 +02:00
|
|
|
af.rgoAction = actionMapping;
|
|
|
|
af.guidActionMap = ACTION_MAPPING_GUID;
|
|
|
|
af.dwGenre = 0x01000000; /* DIVIRTUAL_DRIVING_RACE */
|
2011-06-28 18:54:49 +02:00
|
|
|
af.dwBufferSize = 32;
|
2011-04-30 00:29:19 +02:00
|
|
|
|
2011-07-08 20:00:21 +02:00
|
|
|
/* This enumeration builds and sets the action map for all devices */
|
2017-03-02 19:51:40 +01:00
|
|
|
data.pDI = pDI;
|
2011-07-08 20:00:21 +02:00
|
|
|
hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, &data, DIEDBSFL_ATTACHEDONLY);
|
2011-06-28 18:54:20 +02:00
|
|
|
ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr);
|
2011-04-30 00:29:19 +02:00
|
|
|
|
2019-02-21 14:54:15 +01:00
|
|
|
if (data.keyboard)
|
|
|
|
IDirectInputDevice_Release(data.keyboard);
|
|
|
|
|
|
|
|
if (data.mouse)
|
|
|
|
IDirectInputDevice_Release(data.mouse);
|
|
|
|
|
2011-10-22 22:53:21 +02:00
|
|
|
/* Repeat tests with a non NULL user */
|
|
|
|
data.username = "Ninja Brian";
|
|
|
|
hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &af, enumeration_callback, &data, DIEDBSFL_ATTACHEDONLY);
|
|
|
|
ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr);
|
|
|
|
|
2014-03-07 01:49:58 +01:00
|
|
|
hwnd = CreateWindowExA(WS_EX_TOPMOST, "static", "dinput",
|
|
|
|
WS_POPUP | WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, NULL, NULL);
|
|
|
|
ok(hwnd != NULL, "failed to create window\n");
|
|
|
|
SetCursorPos(50, 50);
|
|
|
|
|
2011-06-28 18:54:49 +02:00
|
|
|
if (data.keyboard != NULL)
|
|
|
|
{
|
|
|
|
/* Test keyboard BuildActionMap */
|
2011-07-02 06:06:01 +02:00
|
|
|
test_build_action_map(data.keyboard, data.lpdiaf, DITEST_KEYBOARDSPACE, DIDFT_PSHBUTTON, DIK_SPACE);
|
2011-06-28 18:54:49 +02:00
|
|
|
/* Test keyboard input */
|
2021-05-26 13:10:58 +02:00
|
|
|
test_device_input(data.keyboard, INPUT_KEYBOARD, DIK_SPACE, 2);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
2021-03-08 13:36:09 +01:00
|
|
|
/* setting format should reset action map */
|
|
|
|
hr = IDirectInputDevice8_SetDataFormat(data.keyboard, &c_dfDIKeyboard);
|
|
|
|
ok (SUCCEEDED(hr), "IDirectInputDevice8_SetDataFormat failed: %08x\n", hr);
|
|
|
|
|
2021-05-26 13:10:58 +02:00
|
|
|
test_device_input(data.keyboard, INPUT_KEYBOARD, DIK_SPACE, -1);
|
2021-03-08 13:36:09 +01:00
|
|
|
|
|
|
|
/* back to action map */
|
|
|
|
hr = IDirectInputDevice8_SetActionMap(data.keyboard, data.lpdiaf, NULL, 0);
|
|
|
|
ok (SUCCEEDED(hr), "SetActionMap should succeed hr=%08x\n", hr);
|
|
|
|
|
2021-05-26 13:10:58 +02:00
|
|
|
test_device_input(data.keyboard, INPUT_KEYBOARD, DIK_SPACE, 2);
|
2021-03-08 13:36:09 +01:00
|
|
|
|
2021-03-08 13:36:11 +01:00
|
|
|
test_appdata_property_vs_map(&data);
|
|
|
|
|
2011-06-28 18:54:49 +02:00
|
|
|
/* Test BuildActionMap with no suitable actions for a device */
|
|
|
|
IDirectInputDevice_Unacquire(data.keyboard);
|
|
|
|
af.dwDataSize = 4 * DITEST_KEYBOARDSPACE;
|
|
|
|
af.dwNumActions = DITEST_KEYBOARDSPACE;
|
|
|
|
|
2012-08-24 19:04:51 +02:00
|
|
|
hr = IDirectInputDevice8_BuildActionMap(data.keyboard, data.lpdiaf, NULL, DIDBAM_HWDEFAULTS);
|
2011-07-02 06:06:37 +02:00
|
|
|
ok (hr == DI_NOEFFECT, "BuildActionMap should have no effect with no actions hr=%08x\n", hr);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
|
|
|
hr = IDirectInputDevice8_SetActionMap(data.keyboard, data.lpdiaf, NULL, 0);
|
2011-07-02 06:06:54 +02:00
|
|
|
ok (hr == DI_NOEFFECT, "SetActionMap should have no effect with no actions to map hr=%08x\n", hr);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
2018-06-07 23:44:38 +02:00
|
|
|
af.dwDataSize = 4 * ARRAY_SIZE(actionMapping);
|
|
|
|
af.dwNumActions = ARRAY_SIZE(actionMapping);
|
2016-03-31 05:39:21 +02:00
|
|
|
|
|
|
|
/* test DIDSAM_NOUSER */
|
|
|
|
dps.diph.dwSize = sizeof(dps);
|
|
|
|
dps.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
dps.diph.dwObj = 0;
|
|
|
|
dps.diph.dwHow = DIPH_DEVICE;
|
|
|
|
dps.wsz[0] = '\0';
|
|
|
|
|
|
|
|
hr = IDirectInputDevice_GetProperty(data.keyboard, DIPROP_USERNAME, &dps.diph);
|
|
|
|
ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr);
|
|
|
|
ok (dps.wsz[0] != 0, "Expected any username, got=%s\n", wine_dbgstr_w(dps.wsz));
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_SetActionMap(data.keyboard, data.lpdiaf, NULL, DIDSAM_NOUSER);
|
|
|
|
ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
|
|
|
|
|
|
|
|
dps.diph.dwSize = sizeof(dps);
|
|
|
|
dps.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
dps.diph.dwObj = 0;
|
|
|
|
dps.diph.dwHow = DIPH_DEVICE;
|
|
|
|
dps.wsz[0] = '\0';
|
|
|
|
|
|
|
|
hr = IDirectInputDevice_GetProperty(data.keyboard, DIPROP_USERNAME, &dps.diph);
|
|
|
|
ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr);
|
|
|
|
ok (dps.wsz[0] == 0, "Expected empty username, got=%s\n", wine_dbgstr_w(dps.wsz));
|
2019-02-21 14:54:15 +01:00
|
|
|
|
|
|
|
IDirectInputDevice_Release(data.keyboard);
|
2011-06-28 18:54:49 +02:00
|
|
|
}
|
|
|
|
|
2011-07-02 06:06:01 +02:00
|
|
|
if (data.mouse != NULL)
|
|
|
|
{
|
|
|
|
/* Test mouse BuildActionMap */
|
|
|
|
test_build_action_map(data.mouse, data.lpdiaf, DITEST_MOUSEBUTTON0, DIDFT_PSHBUTTON, 0x03);
|
|
|
|
test_build_action_map(data.mouse, data.lpdiaf, DITEST_YAXIS, DIDFT_RELAXIS, 0x01);
|
|
|
|
|
|
|
|
test_device_input(data.mouse, INPUT_MOUSE, MOUSEEVENTF_LEFTDOWN, 3);
|
2019-02-21 14:54:15 +01:00
|
|
|
|
|
|
|
IDirectInputDevice_Release(data.mouse);
|
2011-07-02 06:06:01 +02:00
|
|
|
}
|
2014-03-07 01:49:58 +01:00
|
|
|
|
|
|
|
DestroyWindow(hwnd);
|
2019-02-21 14:54:15 +01:00
|
|
|
IDirectInput_Release(pDI);
|
2011-04-30 00:29:19 +02:00
|
|
|
}
|
|
|
|
|
2012-08-24 19:04:51 +02:00
|
|
|
static void test_save_settings(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2013-11-08 20:49:48 +01:00
|
|
|
HINSTANCE hinst = GetModuleHandleA(NULL);
|
|
|
|
IDirectInput8A *pDI = NULL;
|
|
|
|
DIACTIONFORMATA af;
|
2012-08-24 19:04:51 +02:00
|
|
|
IDirectInputDevice8A *pKey;
|
|
|
|
|
|
|
|
static const GUID mapping_guid = { 0xcafecafe, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } };
|
2012-08-28 07:23:02 +02:00
|
|
|
static const GUID other_guid = { 0xcafe, 0xcafe, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } };
|
|
|
|
|
2013-11-08 20:49:48 +01:00
|
|
|
static DIACTIONA actions[] = {
|
2012-08-24 19:04:51 +02:00
|
|
|
{ 0, DIKEYBOARD_A , 0, { "Blam" } },
|
|
|
|
{ 1, DIKEYBOARD_B , 0, { "Kapow"} }
|
|
|
|
};
|
|
|
|
static const DWORD results[] = {
|
|
|
|
DIDFT_MAKEINSTANCE(DIK_A) | DIDFT_PSHBUTTON,
|
|
|
|
DIDFT_MAKEINSTANCE(DIK_B) | DIDFT_PSHBUTTON
|
|
|
|
};
|
|
|
|
static const DWORD other_results[] = {
|
|
|
|
DIDFT_MAKEINSTANCE(DIK_C) | DIDFT_PSHBUTTON,
|
|
|
|
DIDFT_MAKEINSTANCE(DIK_D) | DIDFT_PSHBUTTON
|
|
|
|
};
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_DirectInput8, 0, CLSCTX_INPROC_SERVER, &IID_IDirectInput8A, (LPVOID*)&pDI);
|
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION ||
|
|
|
|
hr == DIERR_BETADIRECTINPUTVERSION ||
|
|
|
|
hr == REGDB_E_CLASSNOTREG)
|
|
|
|
{
|
|
|
|
win_skip("ActionMapping requires dinput8\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok (SUCCEEDED(hr), "DirectInput8 Create failed: hr=%08x\n", hr);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IDirectInput8_Initialize(pDI,hinst, DIRECTINPUT_VERSION);
|
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_BETADIRECTINPUTVERSION)
|
|
|
|
{
|
|
|
|
win_skip("ActionMapping requires dinput8\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok (SUCCEEDED(hr), "DirectInput8 Initialize failed: hr=%08x\n", hr);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKey, NULL);
|
|
|
|
ok (SUCCEEDED(hr), "IDirectInput_Create device failed hr: 0x%08x\n", hr);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
memset (&af, 0, sizeof(af));
|
|
|
|
af.dwSize = sizeof(af);
|
2013-11-08 20:49:48 +01:00
|
|
|
af.dwActionSize = sizeof(DIACTIONA);
|
2018-06-07 23:44:38 +02:00
|
|
|
af.dwDataSize = 4 * ARRAY_SIZE(actions);
|
|
|
|
af.dwNumActions = ARRAY_SIZE(actions);
|
2012-08-24 19:04:51 +02:00
|
|
|
af.rgoAction = actions;
|
|
|
|
af.guidActionMap = mapping_guid;
|
|
|
|
af.dwGenre = 0x01000000; /* DIVIRTUAL_DRIVING_RACE */
|
|
|
|
af.dwBufferSize = 32;
|
|
|
|
|
|
|
|
/* Easy case. Ask for default mapping, save, ask for previous map and read it back */
|
|
|
|
hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, DIDBAM_HWDEFAULTS);
|
|
|
|
ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
|
|
|
|
ok (results[0] == af.rgoAction[0].dwObjID,
|
|
|
|
"Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[0], af.rgoAction[0].dwObjID);
|
|
|
|
|
|
|
|
ok (results[1] == af.rgoAction[1].dwObjID,
|
|
|
|
"Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[1], af.rgoAction[1].dwObjID);
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_SetActionMap(pKey, &af, NULL, DIDSAM_FORCESAVE);
|
|
|
|
ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
|
|
|
|
|
|
|
|
if (hr == DI_SETTINGSNOTSAVED)
|
|
|
|
{
|
2014-02-12 18:53:52 +01:00
|
|
|
skip ("Can't test saving settings if SetActionMap returns DI_SETTINGSNOTSAVED\n");
|
2012-08-24 19:04:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
af.rgoAction[0].dwObjID = 0;
|
|
|
|
af.rgoAction[1].dwObjID = 0;
|
|
|
|
memset(&af.rgoAction[0].guidInstance, 0, sizeof(GUID));
|
|
|
|
memset(&af.rgoAction[1].guidInstance, 0, sizeof(GUID));
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, 0);
|
|
|
|
ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
|
|
|
|
|
|
|
|
ok (results[0] == af.rgoAction[0].dwObjID,
|
|
|
|
"Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[0], af.rgoAction[0].dwObjID);
|
|
|
|
ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[0].guidInstance), "Action should be mapped to keyboard\n");
|
|
|
|
|
|
|
|
ok (results[1] == af.rgoAction[1].dwObjID,
|
|
|
|
"Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[1], af.rgoAction[1].dwObjID);
|
|
|
|
ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[1].guidInstance), "Action should be mapped to keyboard\n");
|
|
|
|
|
2012-08-28 07:23:02 +02:00
|
|
|
/* Test that a different action map with no pre-stored settings, in spite of the flags,
|
|
|
|
does not try to load mappings and instead applies the default mapping */
|
|
|
|
af.guidActionMap = other_guid;
|
|
|
|
|
|
|
|
af.rgoAction[0].dwObjID = 0;
|
|
|
|
af.rgoAction[1].dwObjID = 0;
|
|
|
|
memset(&af.rgoAction[0].guidInstance, 0, sizeof(GUID));
|
|
|
|
memset(&af.rgoAction[1].guidInstance, 0, sizeof(GUID));
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, 0);
|
|
|
|
ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
|
|
|
|
|
2012-08-28 07:23:03 +02:00
|
|
|
ok (results[0] == af.rgoAction[0].dwObjID,
|
2012-08-28 07:23:02 +02:00
|
|
|
"Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[0], af.rgoAction[0].dwObjID);
|
2012-08-28 07:23:03 +02:00
|
|
|
ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[0].guidInstance), "Action should be mapped to keyboard\n");
|
2012-08-28 07:23:02 +02:00
|
|
|
|
2012-08-28 07:23:03 +02:00
|
|
|
ok (results[1] == af.rgoAction[1].dwObjID,
|
2012-08-28 07:23:02 +02:00
|
|
|
"Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[1], af.rgoAction[1].dwObjID);
|
2012-08-28 07:23:03 +02:00
|
|
|
ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[1].guidInstance), "Action should be mapped to keyboard\n");
|
2012-08-28 07:23:02 +02:00
|
|
|
|
|
|
|
af.guidActionMap = mapping_guid;
|
2012-08-24 19:04:51 +02:00
|
|
|
/* Hard case. Customized mapping, save, ask for previous map and read it back */
|
|
|
|
af.rgoAction[0].dwObjID = other_results[0];
|
|
|
|
af.rgoAction[0].dwHow = DIAH_USERCONFIG;
|
|
|
|
af.rgoAction[0].guidInstance = GUID_SysKeyboard;
|
|
|
|
af.rgoAction[1].dwObjID = other_results[1];
|
|
|
|
af.rgoAction[1].dwHow = DIAH_USERCONFIG;
|
|
|
|
af.rgoAction[1].guidInstance = GUID_SysKeyboard;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_SetActionMap(pKey, &af, NULL, DIDSAM_FORCESAVE);
|
|
|
|
ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
|
|
|
|
|
|
|
|
if (hr == DI_SETTINGSNOTSAVED)
|
|
|
|
{
|
2014-02-12 18:53:52 +01:00
|
|
|
skip ("Can't test saving settings if SetActionMap returns DI_SETTINGSNOTSAVED\n");
|
2012-08-24 19:04:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
af.rgoAction[0].dwObjID = 0;
|
|
|
|
af.rgoAction[1].dwObjID = 0;
|
|
|
|
memset(&af.rgoAction[0].guidInstance, 0, sizeof(GUID));
|
|
|
|
memset(&af.rgoAction[1].guidInstance, 0, sizeof(GUID));
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, 0);
|
|
|
|
ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
|
|
|
|
|
2012-08-24 19:04:52 +02:00
|
|
|
ok (other_results[0] == af.rgoAction[0].dwObjID,
|
2012-08-24 19:04:51 +02:00
|
|
|
"Mapped incorrectly expected: 0x%08x got: 0x%08x\n", other_results[0], af.rgoAction[0].dwObjID);
|
2012-08-24 19:04:52 +02:00
|
|
|
ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[0].guidInstance), "Action should be mapped to keyboard\n");
|
2012-08-24 19:04:51 +02:00
|
|
|
|
2012-08-24 19:04:52 +02:00
|
|
|
ok (other_results[1] == af.rgoAction[1].dwObjID,
|
2012-08-24 19:04:51 +02:00
|
|
|
"Mapped incorrectly expected: 0x%08x got: 0x%08x\n", other_results[1], af.rgoAction[1].dwObjID);
|
2012-08-24 19:04:52 +02:00
|
|
|
ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[1].guidInstance), "Action should be mapped to keyboard\n");
|
2019-02-21 14:54:15 +01:00
|
|
|
|
|
|
|
IDirectInputDevice_Release(pKey);
|
|
|
|
IDirectInput_Release(pDI);
|
2012-08-24 19:04:51 +02:00
|
|
|
}
|
|
|
|
|
2019-08-26 16:06:56 +02:00
|
|
|
static void test_mouse_keyboard(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
HWND hwnd, di_hwnd = INVALID_HANDLE_VALUE;
|
|
|
|
IDirectInput8A *di = NULL;
|
|
|
|
IDirectInputDevice8A *di_mouse, *di_keyboard;
|
|
|
|
UINT raw_devices_count;
|
|
|
|
RAWINPUTDEVICE raw_devices[3];
|
|
|
|
|
|
|
|
hwnd = CreateWindowExA(WS_EX_TOPMOST, "static", "dinput", WS_POPUP | WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, NULL, NULL);
|
|
|
|
ok(hwnd != NULL, "CreateWindowExA failed\n");
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_DirectInput8, 0, CLSCTX_INPROC_SERVER, &IID_IDirectInput8A, (LPVOID*)&di);
|
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION ||
|
|
|
|
hr == DIERR_BETADIRECTINPUTVERSION ||
|
|
|
|
hr == REGDB_E_CLASSNOTREG)
|
|
|
|
{
|
|
|
|
win_skip("test_mouse_keyboard requires dinput8\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(SUCCEEDED(hr), "DirectInput8Create failed: %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IDirectInput8_Initialize(di, GetModuleHandleA(NULL), DIRECTINPUT_VERSION);
|
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_BETADIRECTINPUTVERSION)
|
|
|
|
{
|
|
|
|
win_skip("test_mouse_keyboard requires dinput8\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput8_Initialize failed: %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IDirectInput8_CreateDevice(di, &GUID_SysMouse, &di_mouse, NULL);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput8_CreateDevice failed: %08x\n", hr);
|
|
|
|
hr = IDirectInputDevice8_SetDataFormat(di_mouse, &c_dfDIMouse);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_SetDataFormat failed: %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IDirectInput8_CreateDevice(di, &GUID_SysKeyboard, &di_keyboard, NULL);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput8_CreateDevice failed: %08x\n", hr);
|
|
|
|
hr = IDirectInputDevice8_SetDataFormat(di_keyboard, &c_dfDIKeyboard);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_SetDataFormat failed: %08x\n", hr);
|
|
|
|
|
|
|
|
raw_devices_count = ARRAY_SIZE(raw_devices);
|
|
|
|
GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE));
|
|
|
|
ok(raw_devices_count == 0, "Unexpected raw devices registered: %d\n", raw_devices_count);
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_Acquire(di_keyboard);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
|
|
|
|
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);
|
|
|
|
raw_devices_count = ARRAY_SIZE(raw_devices);
|
|
|
|
GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE));
|
|
|
|
ok(raw_devices_count == 0, "Unexpected raw devices registered: %d\n", raw_devices_count);
|
|
|
|
|
|
|
|
if (raw_devices[0].hwndTarget != NULL)
|
2019-08-26 16:06:57 +02:00
|
|
|
{
|
|
|
|
WCHAR str[16];
|
|
|
|
int i;
|
|
|
|
|
2019-08-26 16:06:56 +02:00
|
|
|
di_hwnd = raw_devices[0].hwndTarget;
|
2019-08-26 16:06:57 +02:00
|
|
|
i = GetClassNameW(di_hwnd, str, ARRAY_SIZE(str));
|
2020-10-07 00:52:00 +02:00
|
|
|
ok(i == lstrlenW(L"DIEmWin"), "GetClassName returned incorrect length\n");
|
|
|
|
ok(!lstrcmpW(L"DIEmWin", str), "GetClassName returned incorrect name for this window's class\n");
|
2019-08-26 16:06:57 +02:00
|
|
|
|
|
|
|
i = GetWindowTextW(di_hwnd, str, ARRAY_SIZE(str));
|
2020-10-07 00:52:00 +02:00
|
|
|
ok(i == lstrlenW(L"DIEmWin"), "GetClassName returned incorrect length\n");
|
|
|
|
ok(!lstrcmpW(L"DIEmWin", str), "GetClassName returned incorrect name for this window's class\n");
|
2019-08-26 16:06:57 +02:00
|
|
|
}
|
2019-08-26 16:06:56 +02:00
|
|
|
|
|
|
|
hr = IDirectInputDevice8_Acquire(di_mouse);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
|
|
|
|
raw_devices_count = ARRAY_SIZE(raw_devices);
|
|
|
|
memset(raw_devices, 0, sizeof(raw_devices));
|
|
|
|
hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE));
|
|
|
|
ok(hr == 1, "GetRegisteredRawInputDevices returned %d, raw_devices_count: %d\n", hr, raw_devices_count);
|
|
|
|
ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage);
|
|
|
|
ok(raw_devices[0].usUsage == 2, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage);
|
|
|
|
ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %x\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: %08x\n", hr);
|
|
|
|
raw_devices_count = ARRAY_SIZE(raw_devices);
|
|
|
|
GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE));
|
|
|
|
ok(raw_devices_count == 0, "Unexpected raw devices registered: %d\n", raw_devices_count);
|
|
|
|
|
2020-08-10 11:04:16 +02:00
|
|
|
if (raw_devices[0].hwndTarget != NULL)
|
|
|
|
di_hwnd = raw_devices[0].hwndTarget;
|
|
|
|
|
2019-08-26 16:06:56 +02:00
|
|
|
/* expect dinput8 to take over any activated raw input devices */
|
|
|
|
raw_devices[0].usUsagePage = 0x01;
|
|
|
|
raw_devices[0].usUsage = 0x05;
|
|
|
|
raw_devices[0].dwFlags = 0;
|
|
|
|
raw_devices[0].hwndTarget = hwnd;
|
|
|
|
raw_devices[1].usUsagePage = 0x01;
|
|
|
|
raw_devices[1].usUsage = 0x06;
|
|
|
|
raw_devices[1].dwFlags = 0;
|
|
|
|
raw_devices[1].hwndTarget = hwnd;
|
|
|
|
raw_devices[2].usUsagePage = 0x01;
|
|
|
|
raw_devices[2].usUsage = 0x02;
|
|
|
|
raw_devices[2].dwFlags = 0;
|
|
|
|
raw_devices[2].hwndTarget = hwnd;
|
|
|
|
raw_devices_count = ARRAY_SIZE(raw_devices);
|
|
|
|
hr = RegisterRawInputDevices(raw_devices, raw_devices_count, sizeof(RAWINPUTDEVICE));
|
|
|
|
ok(hr == TRUE, "RegisterRawInputDevices failed\n");
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_Acquire(di_keyboard);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
|
|
|
|
hr = IDirectInputDevice8_Acquire(di_mouse);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
|
|
|
|
raw_devices_count = ARRAY_SIZE(raw_devices);
|
|
|
|
memset(raw_devices, 0, sizeof(raw_devices));
|
|
|
|
hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE));
|
|
|
|
ok(hr == 3, "GetRegisteredRawInputDevices returned %d, raw_devices_count: %d\n", hr, raw_devices_count);
|
|
|
|
ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage);
|
|
|
|
ok(raw_devices[0].usUsage == 2, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage);
|
|
|
|
ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %x\n", raw_devices[0].dwFlags);
|
|
|
|
ok(raw_devices[0].hwndTarget == di_hwnd, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget);
|
|
|
|
ok(raw_devices[1].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[1].usUsagePage);
|
|
|
|
ok(raw_devices[1].usUsage == 5, "Unexpected raw device usage: %x\n", raw_devices[1].usUsage);
|
|
|
|
ok(raw_devices[1].dwFlags == 0, "Unexpected raw device flags: %x\n", raw_devices[1].dwFlags);
|
|
|
|
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);
|
|
|
|
hr = IDirectInputDevice8_Unacquire(di_mouse);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\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);
|
|
|
|
|
2020-08-10 11:04:14 +02:00
|
|
|
IDirectInputDevice8_SetCooperativeLevel(di_mouse, hwnd, DISCL_FOREGROUND|DISCL_EXCLUSIVE);
|
|
|
|
IDirectInputDevice8_SetCooperativeLevel(di_keyboard, hwnd, DISCL_FOREGROUND|DISCL_EXCLUSIVE);
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_Acquire(di_keyboard);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
|
|
|
|
hr = IDirectInputDevice8_Acquire(di_mouse);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
|
|
|
|
raw_devices_count = ARRAY_SIZE(raw_devices);
|
|
|
|
memset(raw_devices, 0, sizeof(raw_devices));
|
|
|
|
hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE));
|
|
|
|
ok(hr == 3, "GetRegisteredRawInputDevices returned %d, raw_devices_count: %d\n", hr, raw_devices_count);
|
|
|
|
ok(raw_devices[0].dwFlags == (RIDEV_CAPTUREMOUSE|RIDEV_NOLEGACY), "Unexpected raw device flags: %x\n", raw_devices[0].dwFlags);
|
|
|
|
todo_wine
|
|
|
|
ok(raw_devices[2].dwFlags == (RIDEV_NOHOTKEYS|RIDEV_NOLEGACY), "Unexpected raw device flags: %x\n", raw_devices[1].dwFlags);
|
|
|
|
hr = IDirectInputDevice8_Unacquire(di_keyboard);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
|
|
|
|
hr = IDirectInputDevice8_Unacquire(di_mouse);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
|
|
|
|
|
2019-08-26 16:06:56 +02:00
|
|
|
raw_devices_count = ARRAY_SIZE(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);
|
|
|
|
ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage);
|
|
|
|
ok(raw_devices[0].usUsage == 5, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage);
|
|
|
|
ok(raw_devices[0].dwFlags == 0, "Unexpected raw device flags: %x\n", raw_devices[0].dwFlags);
|
|
|
|
ok(raw_devices[0].hwndTarget == hwnd, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget);
|
|
|
|
|
|
|
|
IDirectInputDevice8_Release(di_mouse);
|
|
|
|
IDirectInputDevice8_Release(di_keyboard);
|
|
|
|
IDirectInput8_Release(di);
|
|
|
|
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
|
|
|
|
2020-04-13 01:40:16 +02:00
|
|
|
static void test_keyboard_events(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
HWND hwnd = INVALID_HANDLE_VALUE;
|
|
|
|
IDirectInput8A *di;
|
|
|
|
IDirectInputDevice8A *di_keyboard;
|
|
|
|
DIPROPDWORD dp;
|
|
|
|
DIDEVICEOBJECTDATA obj_data[10];
|
|
|
|
DWORD data_size;
|
|
|
|
BYTE kbdata[256];
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_DirectInput8, 0, CLSCTX_INPROC_SERVER, &IID_IDirectInput8A, (LPVOID*)&di);
|
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION ||
|
|
|
|
hr == DIERR_BETADIRECTINPUTVERSION ||
|
|
|
|
hr == REGDB_E_CLASSNOTREG)
|
|
|
|
{
|
|
|
|
win_skip("test_keyboard_events requires dinput8\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(SUCCEEDED(hr), "DirectInput8Create failed: %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IDirectInput8_Initialize(di, GetModuleHandleA(NULL), DIRECTINPUT_VERSION);
|
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_BETADIRECTINPUTVERSION)
|
|
|
|
{
|
|
|
|
win_skip("test_keyboard_events requires dinput8\n");
|
|
|
|
IDirectInput8_Release(di);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput8_Initialize failed: %08x\n", hr);
|
|
|
|
|
|
|
|
hwnd = CreateWindowExA(WS_EX_TOPMOST, "static", "dinput", WS_POPUP | WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, NULL, NULL);
|
|
|
|
ok(hwnd != NULL, "CreateWindowExA failed\n");
|
|
|
|
|
|
|
|
hr = IDirectInput8_CreateDevice(di, &GUID_SysKeyboard, &di_keyboard, NULL);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput8_CreateDevice failed: %08x\n", hr);
|
|
|
|
hr = IDirectInputDevice8_SetCooperativeLevel(di_keyboard, hwnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput8_SetCooperativeLevel failed: %08x\n", hr);
|
|
|
|
hr = IDirectInputDevice8_SetDataFormat(di_keyboard, &c_dfDIKeyboard);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_SetDataFormat failed: %08x\n", hr);
|
|
|
|
dp.diph.dwSize = sizeof(DIPROPDWORD);
|
|
|
|
dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
dp.diph.dwObj = 0;
|
|
|
|
dp.diph.dwHow = DIPH_DEVICE;
|
|
|
|
dp.dwData = ARRAY_SIZE(obj_data);
|
|
|
|
IDirectInputDevice8_SetProperty(di_keyboard, DIPROP_BUFFERSIZE, &(dp.diph));
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_Acquire(di_keyboard);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
|
|
|
|
|
|
|
|
/* Test injecting keyboard events with both VK and scancode given. */
|
|
|
|
keybd_event(VK_SPACE, DIK_SPACE, 0, 0);
|
|
|
|
flush_events();
|
|
|
|
IDirectInputDevice8_Poll(di_keyboard);
|
|
|
|
data_size = ARRAY_SIZE(obj_data);
|
|
|
|
hr = IDirectInputDevice8_GetDeviceData(di_keyboard, sizeof(DIDEVICEOBJECTDATA), obj_data, &data_size, 0);
|
|
|
|
ok(SUCCEEDED(hr), "Failed to get data hr=%08x\n", hr);
|
|
|
|
ok(data_size == 1, "Expected 1 element, received %d\n", data_size);
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_GetDeviceState(di_keyboard, sizeof(kbdata), kbdata);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_GetDeviceState failed: %08x\n", hr);
|
|
|
|
ok(kbdata[DIK_SPACE], "Expected DIK_SPACE key state down\n");
|
|
|
|
|
|
|
|
keybd_event(VK_SPACE, DIK_SPACE, KEYEVENTF_KEYUP, 0);
|
|
|
|
flush_events();
|
|
|
|
IDirectInputDevice8_Poll(di_keyboard);
|
|
|
|
data_size = ARRAY_SIZE(obj_data);
|
|
|
|
hr = IDirectInputDevice8_GetDeviceData(di_keyboard, sizeof(DIDEVICEOBJECTDATA), obj_data, &data_size, 0);
|
|
|
|
ok(SUCCEEDED(hr), "Failed to get data hr=%08x\n", hr);
|
|
|
|
ok(data_size == 1, "Expected 1 element, received %d\n", data_size);
|
|
|
|
|
|
|
|
/* Test injecting keyboard events with scancode=0.
|
|
|
|
* Windows DInput ignores the VK, sets scancode 0 to be pressed, and GetDeviceData returns no elements. */
|
|
|
|
keybd_event(VK_SPACE, 0, 0, 0);
|
|
|
|
flush_events();
|
|
|
|
IDirectInputDevice8_Poll(di_keyboard);
|
|
|
|
data_size = ARRAY_SIZE(obj_data);
|
|
|
|
hr = IDirectInputDevice8_GetDeviceData(di_keyboard, sizeof(DIDEVICEOBJECTDATA), obj_data, &data_size, 0);
|
|
|
|
ok(SUCCEEDED(hr), "Failed to get data hr=%08x\n", hr);
|
|
|
|
ok(data_size == 0, "Expected 0 elements, received %d\n", data_size);
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_GetDeviceState(di_keyboard, sizeof(kbdata), kbdata);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_GetDeviceState failed: %08x\n", hr);
|
|
|
|
todo_wine
|
|
|
|
ok(kbdata[0], "Expected key 0 state down\n");
|
|
|
|
|
|
|
|
keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0);
|
|
|
|
flush_events();
|
|
|
|
IDirectInputDevice8_Poll(di_keyboard);
|
|
|
|
data_size = ARRAY_SIZE(obj_data);
|
|
|
|
hr = IDirectInputDevice8_GetDeviceData(di_keyboard, sizeof(DIDEVICEOBJECTDATA), obj_data, &data_size, 0);
|
|
|
|
ok(SUCCEEDED(hr), "Failed to get data hr=%08x\n", hr);
|
|
|
|
ok(data_size == 0, "Expected 0 elements, received %d\n", data_size);
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_Unacquire(di_keyboard);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_Unacquire failed: %08x\n", hr);
|
|
|
|
|
|
|
|
IDirectInputDevice8_Release(di_keyboard);
|
|
|
|
IDirectInput8_Release(di);
|
|
|
|
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
|
|
|
|
2021-03-08 13:36:11 +01:00
|
|
|
static void test_appdata_property(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
HINSTANCE hinst = GetModuleHandleA(NULL);
|
|
|
|
IDirectInputDevice8A *di_keyboard;
|
|
|
|
IDirectInput8A *pDI = NULL;
|
|
|
|
HWND hwnd;
|
|
|
|
DIPROPDWORD dw;
|
|
|
|
DIPROPPOINTER dp;
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_DirectInput8, 0, CLSCTX_INPROC_SERVER, &IID_IDirectInput8A, (LPVOID*)&pDI);
|
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION ||
|
|
|
|
hr == DIERR_BETADIRECTINPUTVERSION ||
|
|
|
|
hr == REGDB_E_CLASSNOTREG)
|
|
|
|
{
|
|
|
|
win_skip("DIPROP_APPDATA requires dinput8\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(SUCCEEDED(hr), "DirectInput8 Create failed: hr=%08x\n", hr);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IDirectInput8_Initialize(pDI,hinst, DIRECTINPUT_VERSION);
|
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_BETADIRECTINPUTVERSION)
|
|
|
|
{
|
|
|
|
win_skip("DIPROP_APPDATA requires dinput8\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(SUCCEEDED(hr), "DirectInput8 Initialize failed: hr=%08x\n", hr);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hwnd = CreateWindowExA(WS_EX_TOPMOST, "static", "dinput",
|
|
|
|
WS_POPUP | WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, NULL, NULL);
|
|
|
|
ok(hwnd != NULL, "failed to create window\n");
|
|
|
|
|
|
|
|
hr = IDirectInput8_CreateDevice(pDI, &GUID_SysKeyboard, &di_keyboard, NULL);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput8_CreateDevice failed: %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_SetDataFormat(di_keyboard, &c_dfDIKeyboard);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_SetDataFormat failed: %08x\n", hr);
|
|
|
|
|
|
|
|
dw.diph.dwSize = sizeof(DIPROPDWORD);
|
|
|
|
dw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
dw.diph.dwObj = 0;
|
|
|
|
dw.diph.dwHow = DIPH_DEVICE;
|
|
|
|
dw.dwData = 32;
|
|
|
|
hr = IDirectInputDevice8_SetProperty(di_keyboard, DIPROP_BUFFERSIZE, &(dw.diph));
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_SetProperty failed hr=%08x\n", hr);
|
|
|
|
|
|
|
|
/* the default value */
|
2021-05-26 13:10:58 +02:00
|
|
|
test_device_input(di_keyboard, INPUT_KEYBOARD, DIK_A, -1);
|
2021-03-08 13:36:11 +01:00
|
|
|
|
|
|
|
dp.diph.dwHow = DIPH_DEVICE;
|
|
|
|
dp.diph.dwObj = 0;
|
|
|
|
dp.uData = 1;
|
|
|
|
hr = IDirectInputDevice8_SetProperty(di_keyboard, DIPROP_APPDATA, &(dp.diph));
|
|
|
|
ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice8_SetProperty APPDATA for the device should be invalid hr=%08x\n", hr);
|
|
|
|
|
|
|
|
dp.diph.dwSize = sizeof(dp);
|
|
|
|
dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
dp.diph.dwHow = DIPH_BYUSAGE;
|
|
|
|
dp.diph.dwObj = 2;
|
|
|
|
dp.uData = 2;
|
|
|
|
hr = IDirectInputDevice8_SetProperty(di_keyboard, DIPROP_APPDATA, &(dp.diph));
|
|
|
|
ok(hr == DIERR_UNSUPPORTED, "IDirectInputDevice8_SetProperty APPDATA by usage should be unsupported hr=%08x\n", hr);
|
|
|
|
|
|
|
|
dp.diph.dwHow = DIPH_BYID;
|
|
|
|
dp.diph.dwObj = DIDFT_MAKEINSTANCE(DIK_SPACE) | DIDFT_PSHBUTTON;
|
|
|
|
dp.uData = 3;
|
|
|
|
hr = IDirectInputDevice8_SetProperty(di_keyboard, DIPROP_APPDATA, &(dp.diph));
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_SetProperty failed hr=%08x\n", hr);
|
|
|
|
|
|
|
|
dp.diph.dwHow = DIPH_BYOFFSET;
|
|
|
|
dp.diph.dwObj = DIK_A;
|
|
|
|
dp.uData = 4;
|
|
|
|
hr = IDirectInputDevice8_SetProperty(di_keyboard, DIPROP_APPDATA, &(dp.diph));
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_SetProperty failed hr=%08x\n", hr);
|
|
|
|
|
|
|
|
dp.diph.dwHow = DIPH_BYOFFSET;
|
|
|
|
dp.diph.dwObj = DIK_B;
|
|
|
|
dp.uData = 5;
|
|
|
|
hr = IDirectInputDevice8_SetProperty(di_keyboard, DIPROP_APPDATA, &(dp.diph));
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_SetProperty failed hr=%08x\n", hr);
|
|
|
|
|
2021-05-26 13:10:58 +02:00
|
|
|
test_device_input(di_keyboard, INPUT_KEYBOARD, DIK_SPACE, 3);
|
|
|
|
test_device_input(di_keyboard, INPUT_KEYBOARD, DIK_A, 4);
|
|
|
|
test_device_input(di_keyboard, INPUT_KEYBOARD, DIK_B, 5);
|
|
|
|
test_device_input(di_keyboard, INPUT_KEYBOARD, DIK_C, -1);
|
2021-03-08 13:36:11 +01:00
|
|
|
|
|
|
|
/* setting data format resets APPDATA */
|
|
|
|
hr = IDirectInputDevice8_SetDataFormat(di_keyboard, &c_dfDIKeyboard);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice8_SetDataFormat failed: %08x\n", hr);
|
|
|
|
|
|
|
|
test_device_input(di_keyboard, INPUT_KEYBOARD, VK_SPACE, -1);
|
2021-05-26 13:10:58 +02:00
|
|
|
test_device_input(di_keyboard, INPUT_KEYBOARD, DIK_A, -1);
|
|
|
|
test_device_input(di_keyboard, INPUT_KEYBOARD, DIK_B, -1);
|
|
|
|
test_device_input(di_keyboard, INPUT_KEYBOARD, DIK_C, -1);
|
2021-03-08 13:36:11 +01:00
|
|
|
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
IDirectInputDevice_Release(di_keyboard);
|
|
|
|
IDirectInput_Release(pDI);
|
|
|
|
}
|
|
|
|
|
2011-04-30 00:29:19 +02:00
|
|
|
START_TEST(device)
|
|
|
|
{
|
|
|
|
CoInitialize(NULL);
|
|
|
|
|
|
|
|
test_action_mapping();
|
2012-08-24 19:04:51 +02:00
|
|
|
test_save_settings();
|
2019-08-26 16:06:56 +02:00
|
|
|
test_mouse_keyboard();
|
2020-04-13 01:40:16 +02:00
|
|
|
test_keyboard_events();
|
2021-03-08 13:36:11 +01:00
|
|
|
test_appdata_property();
|
2011-04-30 00:29:19 +02:00
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|