[PATCH v2 2/3] user32: Implement SendInput INPUT_HARDWARE check.
Rémi Bernon
rbernon at codeweavers.com
Tue Mar 9 12:39:31 CST 2021
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
dlls/user32/input.c | 22 ++++++++++++++++------
dlls/user32/tests/input.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/dlls/user32/input.c b/dlls/user32/input.c
index e9a74f177b9..03d853d2f48 100644
--- a/dlls/user32/input.c
+++ b/dlls/user32/input.c
@@ -179,8 +179,9 @@ static void update_mouse_coords( INPUT *input )
*/
UINT WINAPI SendInput( UINT count, LPINPUT inputs, int size )
{
+ NTSTATUS status = STATUS_SUCCESS;
+ INPUT tmp;
UINT i;
- NTSTATUS status;
if (size != sizeof(INPUT))
{
@@ -202,14 +203,23 @@ UINT WINAPI SendInput( UINT count, LPINPUT inputs, int size )
for (i = 0; i < count; i++)
{
- if (inputs[i].type == INPUT_MOUSE)
+ memcpy( &tmp, (char *)inputs + i * size, size );
+
+ switch (tmp.type)
{
+ case INPUT_MOUSE:
/* we need to update the coordinates to what the server expects */
- INPUT input = inputs[i];
- update_mouse_coords( &input );
- status = send_hardware_message( 0, &input, SEND_HWMSG_INJECTED );
+ update_mouse_coords( &tmp );
+ /* fallthrough */
+ case INPUT_KEYBOARD:
+ status = send_hardware_message( 0, &tmp, SEND_HWMSG_INJECTED );
+ break;
+#ifdef _WIN64
+ case INPUT_HARDWARE:
+ SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
+ return 0;
+#endif
}
- else status = send_hardware_message( 0, &inputs[i], SEND_HWMSG_INJECTED );
if (status)
{
diff --git a/dlls/user32/tests/input.c b/dlls/user32/tests/input.c
index 7e8829ce375..f4193c66653 100644
--- a/dlls/user32/tests/input.c
+++ b/dlls/user32/tests/input.c
@@ -4123,6 +4123,7 @@ static void test_SendInput(void)
INPUT input[16];
UINT res, i;
HWND hwnd;
+ MSG msg;
hwnd = CreateWindowW( L"static", L"test", WS_OVERLAPPED, 0, 0, 100, 100, 0, 0, 0, 0 );
ok(hwnd != 0, "CreateWindowW failed\n");
@@ -4176,6 +4177,38 @@ static void test_SendInput(void)
ok(res == 16 && GetLastError() == 0xdeadbeef, "SendInput returned %u, error %#x\n", res, GetLastError());
empty_message_queue();
+ for (i = 0; i < ARRAY_SIZE(input); ++i) input[i].type = INPUT_HARDWARE;
+ SetLastError(0xdeadbeef);
+ res = SendInput(16, input, offsetof(INPUT, hi) + sizeof(HARDWAREINPUT));
+ ok(res == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "SendInput returned %u, error %#x\n", res, GetLastError());
+ SetLastError(0xdeadbeef);
+ res = SendInput(16, input, sizeof(*input));
+#ifdef _WIN64
+ ok(res == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED, "SendInput returned %u, error %#x\n", res, GetLastError());
+#else
+ ok(res == 16 && GetLastError() == 0xdeadbeef, "SendInput returned %u, error %#x\n", res, GetLastError());
+#endif
+ while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) ok(0, "SendInput triggered unexpected message %#x\n", msg.message);
+
+ memset(input, 0, sizeof(input));
+ input[0].type = INPUT_HARDWARE;
+ input[1].type = INPUT_KEYBOARD;
+ SetLastError(0xdeadbeef);
+ res = SendInput(16, input, sizeof(*input));
+#ifdef _WIN64
+ ok(res == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED, "SendInput returned %u, error %#x\n", res, GetLastError());
+ while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) ok(0, "SendInput triggered unexpected message %#x\n", msg.message);
+#else
+ ok(res == 16 && GetLastError() == 0xdeadbeef, "SendInput returned %u, error %#x\n", res, GetLastError());
+ while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) ok(msg.message == WM_KEYDOWN, "SendInput triggered unexpected message %#x\n", msg.message);
+#endif
+
+ for (i = 0; i < ARRAY_SIZE(input); ++i) input[i].type = INPUT_HARDWARE + 1;
+ SetLastError(0xdeadbeef);
+ res = SendInput(16, input, sizeof(*input));
+ ok(res == 16 && GetLastError() == 0xdeadbeef, "SendInput returned %u, error %#x\n", res, GetLastError());
+ while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) ok(0, "SendInput triggered unexpected message %#x\n", msg.message);
+
trace("done\n");
DestroyWindow(hwnd);
}
--
2.30.0
More information about the wine-devel
mailing list