diff --git a/libs/enigo/src/win/win_impl.rs b/libs/enigo/src/win/win_impl.rs index 73917cde4..cf4735bb6 100644 --- a/libs/enigo/src/win/win_impl.rs +++ b/libs/enigo/src/win/win_impl.rs @@ -176,13 +176,13 @@ impl KeyboardControllable for Enigo { } fn key_click(&mut self, key: Key) { - let scancode = self.key_to_scancode(key); - keybd_event(KEYEVENTF_SCANCODE, 0, scancode); - keybd_event(KEYEVENTF_KEYUP | KEYEVENTF_SCANCODE, 0, scancode); + let vk = self.key_to_keycode(key); + keybd_event(0, vk, 0); + keybd_event(KEYEVENTF_KEYUP, vk, 0); } fn key_down(&mut self, key: Key) -> crate::ResultType { - let res = keybd_event(KEYEVENTF_SCANCODE, 0, self.key_to_scancode(key)); + let res = keybd_event(0, self.key_to_keycode(key), 0); if res == 0 { let err = get_error(); if !err.is_empty() { @@ -193,11 +193,7 @@ impl KeyboardControllable for Enigo { } fn key_up(&mut self, key: Key) { - keybd_event( - KEYEVENTF_KEYUP | KEYEVENTF_SCANCODE, - 0, - self.key_to_scancode(key), - ); + keybd_event(KEYEVENTF_KEYUP, self.key_to_keycode(key), 0); } fn get_key_state(&mut self, key: Key) -> bool { @@ -345,15 +341,9 @@ impl Enigo { Key::Raw(raw_keycode) => raw_keycode, Key::Layout(c) => self.get_layoutdependent_keycode(c.to_string()), Key::Super | Key::Command | Key::Windows | Key::Meta => EVK_LWIN, - _ => 0, } } - fn key_to_scancode(&self, key: Key) -> u16 { - let keycode = self.key_to_keycode(key); - unsafe { MapVirtualKeyW(keycode as u32, 0) as u16 } - } - fn get_layoutdependent_keycode(&self, string: String) -> u16 { // get the first char from the string ignore the rest // ensure its not a multybyte char diff --git a/libs/hbb_common/Cargo.toml b/libs/hbb_common/Cargo.toml index 360b4dd0f..b778e48a4 100644 --- a/libs/hbb_common/Cargo.toml +++ b/libs/hbb_common/Cargo.toml @@ -13,7 +13,7 @@ tokio-util = { version = "0.6", features = ["full"] } futures = "0.3" bytes = "1.0" log = "0.4" -env_logger = "0.8" +env_logger = "0.9" socket2 = { version = "0.3", features = ["reuseport"] } zstd = "0.9" quinn = {version = "0.6", optional = true } diff --git a/src/server/input_service.rs b/src/server/input_service.rs index 23fa35a1f..3383b9a6b 100644 --- a/src/server/input_service.rs +++ b/src/server/input_service.rs @@ -305,14 +305,12 @@ fn handle_mouse_(evt: &MouseEvent, conn: i32) { let mut en = ENIGO.lock().unwrap(); #[cfg(not(target_os = "macos"))] let mut to_release = Vec::new(); - #[cfg(target_os = "macos")] - en.reset_flag(); - if evt_type == 1 || evt_type == 2 { + if evt_type == 1 { + #[cfg(target_os = "macos")] + en.reset_flag(); fix_modifiers(&evt.modifiers[..], &mut en, 0); - } - for ref ck in evt.modifiers.iter() { - if let Some(key) = KEY_MAP.get(&ck.value()) { - if evt_type == 1 || evt_type == 2 { + for ref ck in evt.modifiers.iter() { + if let Some(key) = KEY_MAP.get(&ck.value()) { #[cfg(target_os = "macos")] en.add_flag(key); #[cfg(not(target_os = "macos"))] @@ -511,30 +509,32 @@ fn handle_key_(evt: &KeyEvent) { let mut has_cap = false; #[cfg(windows)] let mut has_numlock = false; - let ck = if let Some(key_event::Union::control_key(ck)) = evt.union { - ck.value() - } else { - -1 - }; - fix_modifiers(&evt.modifiers[..], &mut en, ck); - for ref ck in evt.modifiers.iter() { - if let Some(key) = KEY_MAP.get(&ck.value()) { - #[cfg(target_os = "macos")] - en.add_flag(key); - #[cfg(not(target_os = "macos"))] - { - if key == &Key::CapsLock { - has_cap = true; - } else if key == &Key::NumLock { - #[cfg(windows)] - { - has_numlock = true; - } - } else { - if !get_modifier_state(key.clone(), &mut en) { - en.key_down(key.clone()).ok(); - modifier_sleep(); - to_release.push(key); + if evt.down { + let ck = if let Some(key_event::Union::control_key(ck)) = evt.union { + ck.value() + } else { + -1 + }; + fix_modifiers(&evt.modifiers[..], &mut en, ck); + for ref ck in evt.modifiers.iter() { + if let Some(key) = KEY_MAP.get(&ck.value()) { + #[cfg(target_os = "macos")] + en.add_flag(key); + #[cfg(not(target_os = "macos"))] + { + if key == &Key::CapsLock { + has_cap = true; + } else if key == &Key::NumLock { + #[cfg(windows)] + { + has_numlock = true; + } + } else { + if !get_modifier_state(key.clone(), &mut en) { + en.key_down(key.clone()).ok(); + modifier_sleep(); + to_release.push(key); + } } } }