more control keys, and VkKeyScanW -> VkKeyScanExW with forground window

keyboard layout
This commit is contained in:
open-trade
2022-01-12 18:11:42 +08:00
parent 8ea5d80f01
commit 3aebc43111
2 changed files with 10 additions and 1 deletions

View File

@@ -350,7 +350,10 @@ impl Enigo {
// NOTE VkKeyScanW uses the current keyboard layout
// to specify a layout use VkKeyScanExW and GetKeyboardLayout
// or load one with LoadKeyboardLayoutW
let keycode_and_shiftstate = unsafe { VkKeyScanW(chr as _) };
let current_window_thread_id =
unsafe { GetWindowThreadProcessId(GetForegroundWindow(), std::ptr::null_mut()) };
let layout = unsafe { GetKeyboardLayout(current_window_thread_id) };
let keycode_and_shiftstate = unsafe { VkKeyScanExW(chr as _, layout) };
keycode_and_shiftstate as _
} else {
0