https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a602bc355054c081e62e6…
commit a602bc355054c081e62e6b0fd0fcbb96d48845ed
Author: Arjav Garg <arjavgarg(a)gmail.com>
AuthorDate: Sun Sep 5 02:04:38 2021 +0530
Commit: Thomas Faber <thomas.faber(a)reactos.org>
CommitDate: Sat Sep 25 09:56:12 2021 -0400
[NTUSER] Fix UserSendKeyboardInput() KEYEVENTF_SCANCODE use case (CORE-17144)
---
modules/rostests/apitests/user32/CMakeLists.txt | 1 +
modules/rostests/apitests/user32/keybd_event.c | 42 +++++++++++++++++++++++++
modules/rostests/apitests/user32/testlist.c | 2 ++
win32ss/user/ntuser/keyboard.c | 5 ++-
4 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/modules/rostests/apitests/user32/CMakeLists.txt
b/modules/rostests/apitests/user32/CMakeLists.txt
index 99d7b4d3168..bafd3571df5 100644
--- a/modules/rostests/apitests/user32/CMakeLists.txt
+++ b/modules/rostests/apitests/user32/CMakeLists.txt
@@ -23,6 +23,7 @@ list(APPEND SOURCE
GetUserObjectInformation.c
GetWindowPlacement.c
InitializeLpkHooks.c
+ keybd_event.c
LoadImage.c
LookupIconIdFromDirectoryEx.c
MessageStateAnalyzer.c
diff --git a/modules/rostests/apitests/user32/keybd_event.c
b/modules/rostests/apitests/user32/keybd_event.c
new file mode 100644
index 00000000000..39475e883ae
--- /dev/null
+++ b/modules/rostests/apitests/user32/keybd_event.c
@@ -0,0 +1,42 @@
+/*
+ * PROJECT: ReactOS api tests
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE: Test for keyboard inputs with flags KEYEVENTF_EXTENDEDKEY and
KEYEVENTF_SCANCODE
+ * COPYRIGHT: Copyright 2021 Arjav Garg <arjavgarg(a)gmail.com>
+ */
+
+#include "precomp.h"
+
+static void testScancodeExtendedKey(BYTE wVk, BYTE scanCode)
+{
+ trace("wVK: %x\tScancode: %x\n", wVk, scanCode);
+
+ keybd_event(0, scanCode, KEYEVENTF_SCANCODE | KEYEVENTF_EXTENDEDKEY, 0);
+ SHORT winKeyState = GetAsyncKeyState(wVk);
+ ok(winKeyState & 0x8000, "VK=%x should be detected as key down.\n",
wVk);
+
+ keybd_event(0, scanCode, KEYEVENTF_SCANCODE | KEYEVENTF_EXTENDEDKEY |
KEYEVENTF_KEYUP, 0);
+ winKeyState = GetAsyncKeyState(wVk);
+ ok(!(winKeyState & 0x8000), "VK=%x should be detected as key up.\n",
wVk);
+}
+
+/*
https://docs.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-inpu…
*/
+START_TEST(keybd_event)
+{
+ testScancodeExtendedKey(VK_RWIN, 0x5C);
+ testScancodeExtendedKey(VK_LWIN, 0x5B);
+ testScancodeExtendedKey(VK_RMENU, 0x38);
+ testScancodeExtendedKey(VK_RCONTROL, 0x1D);
+ testScancodeExtendedKey(VK_INSERT, 0x52);
+ testScancodeExtendedKey(VK_DELETE, 0x53);
+ testScancodeExtendedKey(VK_HOME, 0x47);
+ testScancodeExtendedKey(VK_END, 0x4f);
+ testScancodeExtendedKey(VK_PRIOR, 0x49);
+ testScancodeExtendedKey(VK_NEXT, 0x51);
+ testScancodeExtendedKey(VK_UP, 0x48);
+ testScancodeExtendedKey(VK_RIGHT, 0x4d);
+ testScancodeExtendedKey(VK_LEFT, 0x4b);
+ testScancodeExtendedKey(VK_DOWN, 0x50);
+ testScancodeExtendedKey(VK_DIVIDE, 0x35);
+ testScancodeExtendedKey(VK_RETURN, 0x1C);
+}
diff --git a/modules/rostests/apitests/user32/testlist.c
b/modules/rostests/apitests/user32/testlist.c
index 26325af0571..b372365501c 100644
--- a/modules/rostests/apitests/user32/testlist.c
+++ b/modules/rostests/apitests/user32/testlist.c
@@ -25,6 +25,7 @@ extern void func_GetSystemMetrics(void);
extern void func_GetUserObjectInformation(void);
extern void func_GetWindowPlacement(void);
extern void func_InitializeLpkHooks(void);
+extern void func_keybd_event(void);
extern void func_LoadImage(void);
extern void func_LookupIconIdFromDirectoryEx(void);
extern void func_MessageStateAnalyzer(void);
@@ -76,6 +77,7 @@ const struct test winetest_testlist[] =
{ "GetUserObjectInformation", func_GetUserObjectInformation },
{ "GetWindowPlacement", func_GetWindowPlacement },
{ "InitializeLpkHooks", func_InitializeLpkHooks },
+ { "keybd_event", func_keybd_event },
{ "LoadImage", func_LoadImage },
{ "LookupIconIdFromDirectoryEx", func_LookupIconIdFromDirectoryEx },
{ "MessageStateAnalyzer", func_MessageStateAnalyzer },
diff --git a/win32ss/user/ntuser/keyboard.c b/win32ss/user/ntuser/keyboard.c
index 61a30b6a0e9..08a7b6861c8 100644
--- a/win32ss/user/ntuser/keyboard.c
+++ b/win32ss/user/ntuser/keyboard.c
@@ -1020,8 +1020,11 @@ UserSendKeyboardInput(KEYBDINPUT *pKbdInput, BOOL bInjected)
}
else
{
- wVk = pKbdInput->wVk & 0xFF;
+ wVk = pKbdInput->wVk;
}
+
+ /* Remove all virtual key flags (KBDEXT, KBDMULTIVK, KBDSPECIAL, KBDNUMPAD) */
+ wVk &= 0xFF;
}
/* If time is given, use it */