mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-18 15:53:00 +08:00
Auto release key
This commit is contained in:
parent
80b01a96db
commit
a2d8c31e85
@ -1,5 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::{HashMap, HashSet},
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, AtomicUsize, Ordering},
|
atomic::{AtomicBool, AtomicUsize, Ordering},
|
||||||
@ -57,6 +57,7 @@ type Video = AssetPtr<video_destination>;
|
|||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref ENIGO: Arc<Mutex<Enigo>> = Arc::new(Mutex::new(Enigo::new()));
|
static ref ENIGO: Arc<Mutex<Enigo>> = Arc::new(Mutex::new(Enigo::new()));
|
||||||
static ref VIDEO: Arc<Mutex<Option<Video>>> = Default::default();
|
static ref VIDEO: Arc<Mutex<Option<Video>>> = Default::default();
|
||||||
|
static ref TO_RELEASE: Arc<Mutex<HashSet<RdevKey>>> = Arc::new(Mutex::new(HashSet::<RdevKey>::new()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_key_state(key: enigo::Key) -> bool {
|
fn get_key_state(key: enigo::Key) -> bool {
|
||||||
@ -732,6 +733,9 @@ impl Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn leave(&mut self) {
|
fn leave(&mut self) {
|
||||||
|
for key in TO_RELEASE.lock().unwrap().iter() {
|
||||||
|
self.map_keyboard_mode(false, *key)
|
||||||
|
}
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
crate::platform::windows::stop_system_key_propagate(false);
|
crate::platform::windows::stop_system_key_propagate(false);
|
||||||
IS_IN.store(false, Ordering::SeqCst);
|
IS_IN.store(false, Ordering::SeqCst);
|
||||||
@ -986,9 +990,11 @@ impl Handler {
|
|||||||
if get_key_state(enigo::Key::CapsLock) {
|
if get_key_state(enigo::Key::CapsLock) {
|
||||||
key_event.modifiers.push(ControlKey::CapsLock.into());
|
key_event.modifiers.push(ControlKey::CapsLock.into());
|
||||||
}
|
}
|
||||||
if get_key_state(enigo::Key::NumLock) {
|
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());
|
key_event.modifiers.push(ControlKey::NumLock.into());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.send_key_event(key_event, 1);
|
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"));
|
let mode = std::env::var("KEYBOARD_MOAD").unwrap_or(String::from("map"));
|
||||||
match mode.as_str() {
|
match mode.as_str() {
|
||||||
"map" => {
|
"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);
|
self.map_keyboard_mode(down_or_up, key);
|
||||||
}
|
}
|
||||||
"legacy" => self.legacy_keyboard_mode(down_or_up, key, evt),
|
"legacy" => self.legacy_keyboard_mode(down_or_up, key, evt),
|
||||||
|
Loading…
Reference in New Issue
Block a user