From 3aebc43111f78e361c8e6265b7186fb6b9a529ef Mon Sep 17 00:00:00 2001 From: open-trade Date: Wed, 12 Jan 2022 18:11:42 +0800 Subject: [PATCH] more control keys, and VkKeyScanW -> VkKeyScanExW with forground window keyboard layout --- libs/enigo/src/win/win_impl.rs | 5 ++++- src/ui/remote.rs | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/enigo/src/win/win_impl.rs b/libs/enigo/src/win/win_impl.rs index 3a6b6215f..091841d43 100644 --- a/libs/enigo/src/win/win_impl.rs +++ b/libs/enigo/src/win/win_impl.rs @@ -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 diff --git a/src/ui/remote.rs b/src/ui/remote.rs index 48efad17e..bd818feac 100644 --- a/src/ui/remote.rs +++ b/src/ui/remote.rs @@ -323,6 +323,12 @@ impl Handler { Key::CapsLock | Key::NumLock | Key::ScrollLock => { return; } + Key::Home => Some(ControlKey::Home), + Key::End => Some(ControlKey::End), + Key::Insert => Some(ControlKey::Insert), + Key::PageUp => Some(ControlKey::PageUp), + Key::PageDown => Some(ControlKey::PageDown), + Key::Pause => Some(ControlKey::Pause), _ => None, }; let mut key_event = KeyEvent::new();