2005-05-11 14:05:17 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2005 Robert Reif
|
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-05-11 14:05:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define DIRECTINPUT_VERSION 0x0700
|
|
|
|
|
2006-10-15 19:30:22 +02:00
|
|
|
#define COBJMACROS
|
2005-05-11 14:05:17 +02:00
|
|
|
#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"
|
|
|
|
|
2018-04-16 16:30:53 +02:00
|
|
|
/* to make things easier with PSDK without a dinput.lib */
|
|
|
|
static HRESULT (WINAPI *pDirectInputCreateA)(HINSTANCE,DWORD,IDirectInputA **,IUnknown *);
|
|
|
|
|
|
|
|
static void pump_messages(void)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessageA(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HKL activate_keyboard_layout(LANGID langid, HKL *hkl_orig)
|
|
|
|
{
|
|
|
|
HKL hkl, hkl_current;
|
|
|
|
char hkl_name[64];
|
|
|
|
|
|
|
|
sprintf(hkl_name, "%08x", langid);
|
|
|
|
trace("Loading keyboard layout %s\n", hkl_name);
|
|
|
|
hkl = LoadKeyboardLayoutA(hkl_name, 0);
|
|
|
|
if (!hkl)
|
|
|
|
{
|
|
|
|
win_skip("Unable to load keyboard layout %s\n", hkl_name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*hkl_orig = ActivateKeyboardLayout(hkl, 0);
|
|
|
|
ok(*hkl_orig != 0, "Unable to activate keyboard layout %s\n", hkl_name);
|
|
|
|
if (!*hkl_orig) return 0;
|
|
|
|
|
|
|
|
hkl_current = GetKeyboardLayout(0);
|
|
|
|
if (LOWORD(hkl_current) != langid)
|
|
|
|
{
|
|
|
|
/* FIXME: Wine can't activate different keyboard layouts.
|
|
|
|
* for testing purposes use this workaround:
|
|
|
|
* setxkbmap us && LANG=en_US.UTF-8 make test
|
|
|
|
* setxkbmap fr && LANG=fr_FR.UTF-8 make test
|
|
|
|
* setxkbmap de && LANG=de_DE.UTF-8 make test
|
|
|
|
*/
|
|
|
|
skip("current %08x != langid %08x\n", LOWORD(hkl_current), langid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hkl;
|
|
|
|
}
|
|
|
|
|
2013-10-29 23:13:02 +01:00
|
|
|
static void acquire_tests(IDirectInputA *pDI, HWND hwnd)
|
2005-05-11 14:05:17 +02:00
|
|
|
{
|
2006-04-02 04:55:00 +02:00
|
|
|
HRESULT hr;
|
2013-10-29 23:13:02 +01:00
|
|
|
IDirectInputDeviceA *pKeyboard;
|
2006-04-02 04:55:00 +02:00
|
|
|
BYTE kbd_state[256];
|
2008-07-27 17:53:34 +02:00
|
|
|
LONG custom_state[6];
|
|
|
|
int i;
|
2008-04-17 23:29:24 +02:00
|
|
|
DIOBJECTDATAFORMAT dodf[] =
|
|
|
|
{
|
2008-07-27 17:53:34 +02:00
|
|
|
{ &GUID_Key, sizeof(LONG) * 0, DIDFT_MAKEINSTANCE(DIK_Q)|DIDFT_BUTTON, 0 },
|
|
|
|
{ &GUID_Key, sizeof(LONG) * 1, DIDFT_MAKEINSTANCE(DIK_W)|DIDFT_BUTTON, 0 },
|
|
|
|
{ &GUID_Key, sizeof(LONG) * 2, DIDFT_MAKEINSTANCE(DIK_E)|DIDFT_BUTTON, 0 },
|
|
|
|
{ &GUID_Key, sizeof(LONG) * 4, DIDFT_MAKEINSTANCE(DIK_R)|DIDFT_BUTTON, 0 },
|
2008-04-17 23:29:24 +02:00
|
|
|
};
|
|
|
|
DIDATAFORMAT df;
|
2018-04-16 16:30:53 +02:00
|
|
|
HKL hkl, hkl_orig;
|
|
|
|
|
|
|
|
hkl = activate_keyboard_layout(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), &hkl_orig);
|
|
|
|
if (!hkl) return;
|
|
|
|
|
2008-04-17 23:29:24 +02:00
|
|
|
df.dwSize = sizeof( df );
|
|
|
|
df.dwObjSize = sizeof( DIOBJECTDATAFORMAT );
|
|
|
|
df.dwFlags = DIDF_RELAXIS;
|
2008-07-27 17:53:34 +02:00
|
|
|
df.dwDataSize = sizeof( custom_state );
|
2018-06-07 23:44:39 +02:00
|
|
|
df.dwNumObjs = ARRAY_SIZE(dodf);
|
2008-04-17 23:29:24 +02:00
|
|
|
df.rgodf = dodf;
|
2006-04-02 04:55:00 +02:00
|
|
|
|
|
|
|
hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
|
2006-10-15 19:30:22 +02:00
|
|
|
if (FAILED(hr)) return;
|
2006-04-02 04:55:00 +02:00
|
|
|
|
|
|
|
hr = IDirectInputDevice_SetDataFormat(pKeyboard, &c_dfDIKeyboard);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
|
2006-04-02 04:55:00 +02:00
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr);
|
2006-04-02 04:55:00 +02:00
|
|
|
hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState(10,) should have failed: %08x\n", hr);
|
2006-04-02 04:55:00 +02:00
|
|
|
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState() should have failed: %08x\n", hr);
|
2006-12-01 18:54:42 +01:00
|
|
|
hr = IDirectInputDevice_Unacquire(pKeyboard);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have failed: %08x\n", hr);
|
2006-04-02 04:55:00 +02:00
|
|
|
hr = IDirectInputDevice_Acquire(pKeyboard);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
|
2006-12-01 18:54:42 +01:00
|
|
|
hr = IDirectInputDevice_Acquire(pKeyboard);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have failed: %08x\n", hr);
|
2006-04-02 04:55:00 +02:00
|
|
|
hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(10,) should have failed: %08x\n", hr);
|
2006-04-02 04:55:00 +02:00
|
|
|
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr);
|
2008-04-17 23:29:24 +02:00
|
|
|
hr = IDirectInputDevice_Unacquire(pKeyboard);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_Uncquire() failed: %08x\n", hr);
|
2008-04-17 23:29:24 +02:00
|
|
|
hr = IDirectInputDevice_SetDataFormat( pKeyboard , &df );
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
|
2008-04-17 23:29:24 +02:00
|
|
|
hr = IDirectInputDevice_Acquire(pKeyboard);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
|
2008-04-24 22:32:32 +02:00
|
|
|
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(custom_state), custom_state);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState(4,) failed: %08x\n", hr);
|
2008-04-24 22:32:32 +02:00
|
|
|
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(256,) should have failed: %08x\n", hr);
|
2006-12-22 18:54:29 +01:00
|
|
|
|
2008-07-27 17:53:34 +02:00
|
|
|
memset(custom_state, 0x56, sizeof(custom_state));
|
|
|
|
IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(custom_state), custom_state);
|
2018-06-07 23:44:39 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(custom_state); i++)
|
2008-07-27 17:53:34 +02:00
|
|
|
ok(custom_state[i] == 0, "Should be zeroed, got 0x%08x\n", custom_state[i]);
|
|
|
|
|
2015-04-11 10:06:05 +02:00
|
|
|
/* simulate some keyboard input */
|
|
|
|
SetFocus(hwnd);
|
2018-04-16 16:30:53 +02:00
|
|
|
pump_messages();
|
|
|
|
|
2015-04-11 10:06:05 +02:00
|
|
|
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);
|
2018-06-07 23:44:39 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(custom_state); i++)
|
2015-04-11 10:06:05 +02:00
|
|
|
ok(custom_state[i] == 0, "Should be zeroed, got 0x%08x\n", custom_state[i]);
|
|
|
|
}
|
2015-05-22 10:45:02 +02:00
|
|
|
keybd_event('Q', 0, KEYEVENTF_KEYUP, 0);
|
2015-04-11 10:06:05 +02:00
|
|
|
|
2006-12-22 18:54:29 +01:00
|
|
|
if (pKeyboard) IUnknown_Release(pKeyboard);
|
2018-04-16 16:30:53 +02:00
|
|
|
|
|
|
|
ActivateKeyboardLayout(hkl_orig, 0);
|
|
|
|
UnloadKeyboardLayout(hkl);
|
2006-10-15 19:30:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const HRESULT SetCoop_null_window[16] = {
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_HANDLE, S_OK, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
|
|
|
|
|
2015-11-24 21:25:58 +01:00
|
|
|
static const HRESULT SetCoop_invalid_window[16] = {
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
|
|
|
|
|
2006-10-15 19:30:22 +02:00
|
|
|
static const HRESULT SetCoop_real_window[16] = {
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, S_OK, S_OK, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_NOTIMPL, S_OK, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
|
|
|
|
|
2011-11-02 06:45:39 +01:00
|
|
|
static const HRESULT SetCoop_child_window[16] = {
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
|
|
|
|
|
2013-10-29 23:13:02 +01:00
|
|
|
static void test_set_coop(IDirectInputA *pDI, HWND hwnd)
|
2006-10-15 19:30:22 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2013-10-29 23:13:02 +01:00
|
|
|
IDirectInputDeviceA *pKeyboard = NULL;
|
2006-10-15 19:30:22 +02:00
|
|
|
int i;
|
2011-11-02 06:45:39 +01:00
|
|
|
HWND child;
|
2006-10-15 19:30:22 +02:00
|
|
|
|
|
|
|
hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
|
2006-10-15 19:30:22 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
for (i=0; i<16; i++)
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, i);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %08x\n", i, hr);
|
2006-10-15 19:30:22 +02:00
|
|
|
}
|
|
|
|
for (i=0; i<16; i++)
|
2015-11-24 21:25:58 +01:00
|
|
|
{
|
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, (HWND)0x400000, i);
|
|
|
|
ok(hr == SetCoop_invalid_window[i], "SetCooperativeLevel(invalid, %d): %08x\n", i, hr);
|
|
|
|
}
|
|
|
|
for (i=0; i<16; i++)
|
2006-10-15 19:30:22 +02:00
|
|
|
{
|
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, hwnd, i);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %08x\n", i, hr);
|
2006-10-15 19:30:22 +02:00
|
|
|
}
|
|
|
|
|
2013-10-29 23:13:02 +01:00
|
|
|
child = CreateWindowA("static", "Title", WS_CHILD | WS_VISIBLE, 10, 10, 50, 50, hwnd, NULL,
|
|
|
|
NULL, NULL);
|
2011-11-02 06:45:39 +01:00
|
|
|
ok(child != NULL, "err: %d\n", GetLastError());
|
|
|
|
|
|
|
|
for (i=0; i<16; i++)
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, child, i);
|
|
|
|
ok(hr == SetCoop_child_window[i], "SetCooperativeLevel(child, %d): %08x\n", i, hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
DestroyWindow(child);
|
2006-10-15 19:30:22 +02:00
|
|
|
if (pKeyboard) IUnknown_Release(pKeyboard);
|
|
|
|
}
|
|
|
|
|
2013-10-29 23:13:02 +01:00
|
|
|
static void test_get_prop(IDirectInputA *pDI, HWND hwnd)
|
2011-05-31 00:31:17 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2013-10-29 23:13:02 +01:00
|
|
|
IDirectInputDeviceA *pKeyboard = NULL;
|
2011-05-31 00:31:17 +02:00
|
|
|
DIPROPRANGE diprg;
|
|
|
|
|
|
|
|
hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
memset(&diprg, 0, sizeof(diprg));
|
|
|
|
diprg.diph.dwSize = sizeof(DIPROPRANGE);
|
|
|
|
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
diprg.diph.dwHow = DIPH_DEVICE;
|
|
|
|
diprg.diph.dwObj = 0;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice_GetProperty(pKeyboard, DIPROP_RANGE, &diprg.diph);
|
|
|
|
ok(hr == DIERR_UNSUPPORTED, "IDirectInputDevice_GetProperty() did not return DIPROP_RANGE but: %08x\n", hr);
|
|
|
|
|
|
|
|
if (pKeyboard) IUnknown_Release(pKeyboard);
|
|
|
|
}
|
|
|
|
|
2013-10-29 23:13:02 +01:00
|
|
|
static void test_capabilities(IDirectInputA *pDI, HWND hwnd)
|
2012-08-20 08:52:16 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2013-10-29 23:13:02 +01:00
|
|
|
IDirectInputDeviceA *pKeyboard = NULL;
|
2012-08-20 08:52:16 +02:00
|
|
|
DIDEVCAPS caps;
|
2018-08-17 10:14:52 +02:00
|
|
|
int kbd_type, kbd_subtype, dev_subtype;
|
2012-08-20 08:52:16 +02:00
|
|
|
|
|
|
|
hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
caps.dwSize = sizeof(caps);
|
|
|
|
hr = IDirectInputDevice_GetCapabilities(pKeyboard, &caps);
|
|
|
|
|
2012-09-03 23:38:53 +02:00
|
|
|
ok (SUCCEEDED(hr), "GetCapabilities failed: 0x%08x\n", hr);
|
|
|
|
ok (caps.dwFlags & DIDC_ATTACHED, "GetCapabilities dwFlags: 0x%08x\n", caps.dwFlags);
|
2018-08-17 10:14:51 +02:00
|
|
|
ok (GET_DIDEVICE_TYPE(caps.dwDevType) == DIDEVTYPE_KEYBOARD,
|
2012-08-20 08:52:16 +02:00
|
|
|
"GetCapabilities invalid device type for dwDevType: 0x%08x\n", caps.dwDevType);
|
2018-08-17 10:14:52 +02:00
|
|
|
kbd_type = GetKeyboardType(0);
|
|
|
|
kbd_subtype = GetKeyboardType(1);
|
|
|
|
dev_subtype = GET_DIDEVICE_SUBTYPE(caps.dwDevType);
|
|
|
|
if (kbd_type == 4 || (kbd_type == 7 && kbd_subtype == 0))
|
|
|
|
ok (dev_subtype == DIDEVTYPEKEYBOARD_PCENH,
|
|
|
|
"GetCapabilities invalid device subtype for dwDevType: 0x%08x (%04x:%04x)\n",
|
|
|
|
caps.dwDevType, kbd_type, kbd_subtype);
|
|
|
|
else if (kbd_type == 7 && kbd_subtype == 2)
|
2018-08-17 10:14:54 +02:00
|
|
|
ok (dev_subtype == DIDEVTYPEKEYBOARD_JAPAN106,
|
2018-08-17 10:14:52 +02:00
|
|
|
"GetCapabilities invalid device subtype for dwDevType: 0x%08x (%04x:%04x)\n",
|
|
|
|
caps.dwDevType, kbd_type, kbd_subtype);
|
|
|
|
else
|
|
|
|
ok (dev_subtype != DIDEVTYPEKEYBOARD_UNKNOWN,
|
|
|
|
"GetCapabilities invalid device subtype for dwDevType: 0x%08x (%04x:%04x)\n",
|
|
|
|
caps.dwDevType, kbd_type, kbd_subtype);
|
2012-08-20 08:52:16 +02:00
|
|
|
|
2012-09-03 19:02:54 +02:00
|
|
|
IUnknown_Release(pKeyboard);
|
2012-08-20 08:52:16 +02:00
|
|
|
}
|
|
|
|
|
2018-04-16 16:30:53 +02:00
|
|
|
static void test_dik_codes(IDirectInputA *dI, HWND hwnd, LANGID langid)
|
|
|
|
{
|
|
|
|
static const struct key2dik
|
|
|
|
{
|
2018-08-17 10:15:00 +02:00
|
|
|
BYTE key, dik, todo;
|
2018-04-16 16:30:53 +02:00
|
|
|
} key2dik_en[] =
|
|
|
|
{
|
2018-08-17 10:15:00 +02:00
|
|
|
{'Q',DIK_Q}, {'W',DIK_W}, {'E',DIK_E}, {'R',DIK_R}, {'T',DIK_T}, {'Y',DIK_Y},
|
|
|
|
{'[',DIK_LBRACKET}, {']',DIK_RBRACKET}, {'.',DIK_PERIOD}
|
2018-04-16 16:30:53 +02:00
|
|
|
},
|
|
|
|
key2dik_fr[] =
|
|
|
|
{
|
2018-08-17 10:15:00 +02:00
|
|
|
{'A',DIK_Q}, {'Z',DIK_W}, {'E',DIK_E}, {'R',DIK_R}, {'T',DIK_T}, {'Y',DIK_Y},
|
|
|
|
{'^',DIK_LBRACKET}, {'$',DIK_RBRACKET}, {':',DIK_PERIOD}
|
2018-04-16 16:30:53 +02:00
|
|
|
},
|
|
|
|
key2dik_de[] =
|
|
|
|
{
|
2018-08-17 10:15:00 +02:00
|
|
|
{'Q',DIK_Q}, {'W',DIK_W}, {'E',DIK_E}, {'R',DIK_R}, {'T',DIK_T}, {'Z',DIK_Y},
|
|
|
|
{'\xfc',DIK_LBRACKET,1}, {'+',DIK_RBRACKET}, {'.',DIK_PERIOD}
|
|
|
|
},
|
|
|
|
key2dik_ja[] =
|
|
|
|
{
|
|
|
|
{'Q',DIK_Q}, {'W',DIK_W}, {'E',DIK_E}, {'R',DIK_R}, {'T',DIK_T}, {'Y',DIK_Y},
|
2018-08-17 10:15:02 +02:00
|
|
|
{'@',DIK_AT}, {']',DIK_RBRACKET}, {'.',DIK_PERIOD}
|
2018-04-16 16:30:53 +02:00
|
|
|
};
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
LANGID langid;
|
|
|
|
const struct key2dik *map;
|
2018-08-17 10:14:58 +02:00
|
|
|
DWORD type;
|
2018-04-16 16:30:53 +02:00
|
|
|
} expected[] =
|
|
|
|
{
|
2018-08-17 10:14:58 +02:00
|
|
|
{ MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
|
|
|
|
key2dik_en, DIDEVTYPEKEYBOARD_PCENH },
|
|
|
|
{ MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH),
|
|
|
|
key2dik_fr, DIDEVTYPEKEYBOARD_PCENH },
|
|
|
|
{ MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN),
|
|
|
|
key2dik_de, DIDEVTYPEKEYBOARD_PCENH },
|
|
|
|
{ MAKELANGID(LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN),
|
2018-08-17 10:15:00 +02:00
|
|
|
key2dik_ja, DIDEVTYPEKEYBOARD_JAPAN106 }
|
2018-04-16 16:30:53 +02:00
|
|
|
};
|
|
|
|
const struct key2dik *map = NULL;
|
|
|
|
UINT i;
|
|
|
|
HRESULT hr;
|
|
|
|
IDirectInputDeviceA *device;
|
2018-08-17 10:14:58 +02:00
|
|
|
DIDEVCAPS caps;
|
2018-04-16 16:30:53 +02:00
|
|
|
HKL hkl, hkl_orig;
|
|
|
|
MSG msg;
|
|
|
|
|
2018-06-07 23:44:39 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(expected); i++)
|
2018-04-16 16:30:53 +02:00
|
|
|
{
|
|
|
|
if (expected[i].langid == langid)
|
|
|
|
{
|
|
|
|
map = expected[i].map;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok(map != NULL, "can't find mapping for langid %04x\n", langid);
|
|
|
|
if (!map) return;
|
|
|
|
|
|
|
|
hr = IDirectInput_CreateDevice(dI, &GUID_SysKeyboard, &device, NULL);
|
|
|
|
ok(hr == S_OK, "CreateDevice() failed: %08x\n", hr);
|
|
|
|
hr = IDirectInputDevice_SetDataFormat(device, &c_dfDIKeyboard);
|
|
|
|
ok(hr == S_OK, "SetDataFormat() failed: %08x\n", hr);
|
|
|
|
hr = IDirectInputDevice_Acquire(device);
|
|
|
|
ok(hr == S_OK, "Acquire() failed: %08x\n", hr);
|
2018-08-17 10:14:58 +02:00
|
|
|
caps.dwSize = sizeof( caps );
|
|
|
|
hr = IDirectInputDevice_GetCapabilities(device, &caps);
|
|
|
|
ok(hr == S_OK, "GetDeviceInstance() failed: %08x\n", hr);
|
|
|
|
if (expected[i].type != GET_DIDEVICE_SUBTYPE(caps.dwDevType)) {
|
|
|
|
skip("Keyboard type(%u) doesn't match for lang %04x\n",
|
|
|
|
GET_DIDEVICE_SUBTYPE(caps.dwDevType), langid);
|
|
|
|
goto fail;
|
|
|
|
}
|
2018-04-16 16:30:53 +02:00
|
|
|
|
|
|
|
hkl = activate_keyboard_layout(langid, &hkl_orig);
|
|
|
|
if (!hkl) goto fail;
|
|
|
|
|
|
|
|
SetFocus(hwnd);
|
|
|
|
pump_messages();
|
|
|
|
|
2018-06-07 23:44:39 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(key2dik_en); i++)
|
2018-04-16 16:30:53 +02:00
|
|
|
{
|
|
|
|
BYTE kbd_state[256];
|
|
|
|
UINT n;
|
2018-08-17 10:15:00 +02:00
|
|
|
WORD vkey, scan;
|
2018-04-16 16:30:53 +02:00
|
|
|
INPUT in;
|
|
|
|
|
2018-08-17 10:15:00 +02:00
|
|
|
n = VkKeyScanExW(map[i].key, hkl);
|
|
|
|
todo_wine_if(map[i].todo & 1)
|
|
|
|
ok(n != 0xffff, "%u: failed to get virtual key value for %c(%02x)\n", i, map[i].key, map[i].key);
|
|
|
|
vkey = LOBYTE(n);
|
|
|
|
n = MapVirtualKeyExA(vkey, MAPVK_VK_TO_CHAR, hkl) & 0xff;
|
|
|
|
todo_wine_if(map[i].todo & 1)
|
|
|
|
ok(n == map[i].key, "%u: expected %c(%02x), got %c(%02x)\n", i, map[i].key, map[i].key, n, n);
|
|
|
|
scan = MapVirtualKeyExA(vkey, MAPVK_VK_TO_VSC, hkl);
|
|
|
|
/* scan codes match the DIK_ codes on US keyboard.
|
|
|
|
however, it isn't true for symbols and punctuations in other layouts. */
|
|
|
|
if (isalpha(map[i].key) || langid == MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT))
|
|
|
|
ok(scan == map[i].dik, "%u: expected %02x, got %02x\n", i, map[i].dik, n);
|
|
|
|
else
|
|
|
|
todo_wine_if(map[i].todo & 1)
|
|
|
|
ok(scan, "%u: fail to get scan code value, expected %02x (vkey=%02x)\n",
|
|
|
|
i, map[i].dik, vkey);
|
2018-04-16 16:30:53 +02:00
|
|
|
|
|
|
|
in.type = INPUT_KEYBOARD;
|
2018-08-17 10:15:00 +02:00
|
|
|
U(in).ki.wVk = vkey;
|
|
|
|
U(in).ki.wScan = scan;
|
2018-04-16 16:30:53 +02:00
|
|
|
U(in).ki.dwFlags = 0;
|
|
|
|
U(in).ki.dwExtraInfo = 0;
|
|
|
|
U(in).ki.time = 0;
|
|
|
|
n = SendInput(1, &in, sizeof(in));
|
|
|
|
ok(n == 1, "got %u\n", n);
|
|
|
|
|
2018-08-17 10:14:56 +02:00
|
|
|
if (!PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE))
|
2018-04-16 16:30:53 +02:00
|
|
|
{
|
2018-12-10 14:58:57 +01:00
|
|
|
U(in).ki.dwFlags = KEYEVENTF_KEYUP;
|
|
|
|
SendInput(1, &in, sizeof(in));
|
2018-04-16 16:30:53 +02:00
|
|
|
win_skip("failed to queue keyboard event\n");
|
|
|
|
break;
|
|
|
|
}
|
2018-08-17 10:14:56 +02:00
|
|
|
ok(msg.message == WM_KEYDOWN, "expected WM_KEYDOWN, got %04x\n", msg.message);
|
2018-04-16 16:30:53 +02:00
|
|
|
DispatchMessageA(&msg);
|
|
|
|
|
2018-08-17 10:15:00 +02:00
|
|
|
n = MapVirtualKeyExA(msg.wParam, MAPVK_VK_TO_CHAR, hkl);
|
|
|
|
trace("keydown wParam: %#08lx (%c) lParam: %#08lx, MapVirtualKey(MAPVK_VK_TO_CHAR) = %c\n",
|
|
|
|
msg.wParam, isprint(LOWORD(msg.wParam)) ? LOWORD(msg.wParam) : '?',
|
|
|
|
msg.lParam, isprint(n) ? n : '?');
|
2018-04-16 16:30:53 +02:00
|
|
|
|
|
|
|
pump_messages();
|
|
|
|
|
|
|
|
hr = IDirectInputDevice_GetDeviceState(device, sizeof(kbd_state), kbd_state);
|
|
|
|
ok(hr == S_OK, "GetDeviceState() failed: %08x\n", hr);
|
|
|
|
|
|
|
|
/* this never happens on real hardware but tesbot VMs seem to have timing issues */
|
|
|
|
if (i == 0 && kbd_state[map[0].dik] != 0x80)
|
|
|
|
{
|
|
|
|
win_skip("dinput failed to handle keyboard event\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-08-17 10:15:00 +02:00
|
|
|
todo_wine_if(map[i].todo)
|
2018-04-16 16:30:53 +02:00
|
|
|
ok(kbd_state[map[i].dik] == 0x80, "DI key %#x has state %#x\n", map[i].dik, kbd_state[map[i].dik]);
|
|
|
|
|
|
|
|
U(in).ki.dwFlags = KEYEVENTF_KEYUP;
|
|
|
|
n = SendInput(1, &in, sizeof(in));
|
|
|
|
ok(n == 1, "got %u\n", n);
|
|
|
|
|
|
|
|
pump_messages();
|
|
|
|
}
|
|
|
|
|
|
|
|
ActivateKeyboardLayout(hkl_orig, 0);
|
|
|
|
UnloadKeyboardLayout(hkl);
|
|
|
|
fail:
|
|
|
|
IDirectInputDevice_Unacquire(device);
|
|
|
|
IUnknown_Release(device);
|
|
|
|
}
|
|
|
|
|
2006-10-15 19:30:22 +02:00
|
|
|
static void keyboard_tests(DWORD version)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2013-10-29 23:13:02 +01:00
|
|
|
IDirectInputA *pDI = NULL;
|
|
|
|
HINSTANCE hInstance = GetModuleHandleW(NULL);
|
2006-10-15 19:30:22 +02:00
|
|
|
HWND hwnd;
|
|
|
|
ULONG ref = 0;
|
|
|
|
|
2018-04-16 16:30:53 +02:00
|
|
|
hr = pDirectInputCreateA(hInstance, version, &pDI, NULL);
|
2008-03-07 20:26:57 +01:00
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION)
|
|
|
|
{
|
|
|
|
skip("Tests require a newer dinput version\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-10-29 23:13:02 +01:00
|
|
|
ok(SUCCEEDED(hr), "DirectInputCreateA() failed: %08x\n", hr);
|
2006-10-15 19:30:22 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
2013-10-29 23:13:02 +01:00
|
|
|
hwnd = CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 10, 10, 200, 200,
|
|
|
|
NULL, NULL, NULL, NULL);
|
2006-10-15 19:30:22 +02:00
|
|
|
ok(hwnd != NULL, "err: %d\n", GetLastError());
|
2018-12-10 14:58:57 +01:00
|
|
|
SetForegroundWindow( hwnd );
|
2006-10-15 19:30:22 +02:00
|
|
|
|
|
|
|
if (hwnd)
|
|
|
|
{
|
2018-04-16 16:30:53 +02:00
|
|
|
pump_messages();
|
|
|
|
|
2006-10-15 19:30:22 +02:00
|
|
|
acquire_tests(pDI, hwnd);
|
|
|
|
test_set_coop(pDI, hwnd);
|
2011-05-31 00:31:17 +02:00
|
|
|
test_get_prop(pDI, hwnd);
|
2012-08-20 08:52:16 +02:00
|
|
|
test_capabilities(pDI, hwnd);
|
2018-04-16 16:30:53 +02:00
|
|
|
|
|
|
|
test_dik_codes(pDI, hwnd, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT));
|
|
|
|
test_dik_codes(pDI, hwnd, MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH));
|
|
|
|
test_dik_codes(pDI, hwnd, MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN));
|
|
|
|
test_dik_codes(pDI, hwnd, MAKELANGID(LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN));
|
2006-10-15 19:30:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
if (pDI) ref = IUnknown_Release(pDI);
|
2006-10-12 02:22:27 +02:00
|
|
|
ok(!ref, "IDirectInput_Release() reference count = %d\n", ref);
|
2005-05-11 14:05:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(keyboard)
|
|
|
|
{
|
2018-08-15 10:48:54 +02:00
|
|
|
pDirectInputCreateA = (void *)GetProcAddress(GetModuleHandleA("dinput.dll"), "DirectInputCreateA");
|
2018-04-16 16:30:53 +02:00
|
|
|
|
2005-05-11 14:05:17 +02:00
|
|
|
CoInitialize(NULL);
|
|
|
|
|
2006-04-02 04:55:00 +02:00
|
|
|
keyboard_tests(0x0700);
|
2005-05-11 14:05:17 +02:00
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|