On Fri May 17 16:01:15 2024 +0000, Rémi Bernon wrote:
What about doing that conditionally, as the driver can provide the full scan code and wouldn't need the KEYEVENTF_EXTENDEDKEY flag. Something like:
if (input->ki.dwFlags & KEYEVENTF_SCANCODE) { UINT scan = input->ki.wScan; /* TODO: Use the keyboard layout of the target hwnd, once * NtUserGetKeyboardLayout supports non-current threads. */ HKL layout = NtUserGetKeyboardLayout( 0 ); if (flags & SEND_HWMSG_INJECTED) { scan = scan & 0xff; if (input->ki.dwFlags & KEYEVENTF_EXTENDEDKEY) scan |= 0xe000; } req->input.kbd.vkey = NtUserMapVirtualKeyEx( scan, MAPVK_VSC_TO_VK_EX, layout ); req->input.kbd.scan = input->ki.wScan & 0xff; } else { req->input.kbd.vkey = input->ki.wVk; req->input.kbd.scan = input->ki.wScan; } req->input.kbd.flags = input->ki.dwFlags & ~KEYEVENTF_SCANCODE;
And then add a test to the SendInput tests above showing that this flag what is used for injected input? Something like:
struct send_input_keyboard_test rctrl_scan[] = { {.scan = 0xe01d, .flags = KEYEVENTF_SCANCODE, .expect_state = {[VK_CONTROL] = 0x80, [VK_LCONTROL] = 0x80}, .todo_state = {[0] = TRUE, [VK_CONTROL] = TRUE, [VK_LCONTROL] = TRUE}, .expect = {KEY_HOOK(WM_KEYDOWN, 0x1d, VK_LCONTROL, .todo_value = TRUE), KEY_MSG(WM_KEYDOWN, 0x1d, VK_CONTROL, .todo_value = TRUE), {0}}}, {.scan = 0xe01d, .flags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP, .expect = {KEY_HOOK(WM_KEYUP, 0x1d, VK_LCONTROL, .todo_value = TRUE), KEY_MSG(WM_KEYUP, 0x1d, VK_CONTROL, .todo_value = TRUE), {0}}}, {.scan = 0x1d, .flags = KEYEVENTF_SCANCODE | KEYEVENTF_EXTENDEDKEY, .expect_state = {[VK_CONTROL] = 0x80, [VK_RCONTROL] = 0x80}, .todo_state = {[0] = TRUE, [VK_CONTROL] = TRUE, [VK_RCONTROL] = TRUE}, .expect = {KEY_HOOK_(WM_KEYDOWN, 0x1d, VK_RCONTROL, LLKHF_EXTENDED, .todo_value = TRUE), KEY_MSG(WM_KEYDOWN, 0x11d, VK_CONTROL, .todo_value = TRUE), {0}}}, {.scan = 0x1d, .flags = KEYEVENTF_SCANCODE | KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, .expect = {KEY_HOOK_(WM_KEYUP, 0x1d, VK_RCONTROL, LLKHF_EXTENDED, .todo_value = TRUE), KEY_MSG(WM_KEYUP, 0x11d, VK_CONTROL, .todo_value = TRUE), {0}}}, {0}, };
Done in v2.