From a2d8c31e856a54eb6ba551d3adefdbbe5135512f Mon Sep 17 00:00:00 2001 From: Asura Date: Mon, 18 Jul 2022 22:01:08 +0800 Subject: [PATCH] Auto release key --- src/ui/remote.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ui/remote.rs b/src/ui/remote.rs index f6031a425..44e7d705f 100644 --- a/src/ui/remote.rs +++ b/src/ui/remote.rs @@ -1,5 +1,5 @@ use std::{ - collections::HashMap, + collections::{HashMap, HashSet}, ops::Deref, sync::{ atomic::{AtomicBool, AtomicUsize, Ordering}, @@ -57,6 +57,7 @@ type Video = AssetPtr; lazy_static::lazy_static! { static ref ENIGO: Arc> = Arc::new(Mutex::new(Enigo::new())); static ref VIDEO: Arc>> = Default::default(); + static ref TO_RELEASE: Arc>> = Arc::new(Mutex::new(HashSet::::new())); } fn get_key_state(key: enigo::Key) -> bool { @@ -732,6 +733,9 @@ impl Handler { } fn leave(&mut self) { + for key in TO_RELEASE.lock().unwrap().iter() { + self.map_keyboard_mode(false, *key) + } #[cfg(windows)] crate::platform::windows::stop_system_key_propagate(false); IS_IN.store(false, Ordering::SeqCst); @@ -986,8 +990,10 @@ impl Handler { if get_key_state(enigo::Key::CapsLock) { key_event.modifiers.push(ControlKey::CapsLock.into()); } - if get_key_state(enigo::Key::NumLock) { - key_event.modifiers.push(ControlKey::NumLock.into()); + if self.peer_platform() != "Mac OS" { + if get_key_state(enigo::Key::NumLock) && common::valid_for_numlock(&key_event) { + key_event.modifiers.push(ControlKey::NumLock.into()); + } } self.send_key_event(key_event, 1); @@ -1257,6 +1263,11 @@ impl Handler { let mode = std::env::var("KEYBOARD_MOAD").unwrap_or(String::from("map")); match mode.as_str() { "map" => { + if down_or_up == true { + TO_RELEASE.lock().unwrap().insert(key); + } else { + TO_RELEASE.lock().unwrap().remove(&key); + } self.map_keyboard_mode(down_or_up, key); } "legacy" => self.legacy_keyboard_mode(down_or_up, key, evt),