From 2c25be346c59da4fddacfb288df4e74019345711 Mon Sep 17 00:00:00 2001 From: fufesou Date: Wed, 5 Apr 2023 13:51:59 +0800 Subject: [PATCH 1/3] fix press/release single meta key Signed-off-by: fufesou --- src/lib.rs | 1 + src/server/input_service.rs | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5dcd6389c..a702e5f11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ /// cbindgen:ignore pub mod platform; mod keyboard; +pub use keyboard::keycode_to_rdev_key; #[cfg(not(any(target_os = "android", target_os = "ios")))] pub use platform::{get_cursor, get_cursor_data, get_cursor_pos, start_os_service}; #[cfg(not(any(target_os = "ios")))] diff --git a/src/server/input_service.rs b/src/server/input_service.rs index 7d3229c12..fb04107ca 100644 --- a/src/server/input_service.rs +++ b/src/server/input_service.rs @@ -1371,6 +1371,35 @@ fn simulate_win2win_hotkey(code: u32, down: bool) { allow_err!(rdev::simulate_code(Some(keycode), None, down)); } +#[cfg(any(target_os = "android", target_os = "ios"))] +fn is_meta_key(_evt: &KeyEvent) -> bool { + false +} + +#[cfg(not(any(target_os = "android", target_os = "ios")))] +fn is_meta_key(evt: &KeyEvent) -> bool { + match evt.mode.unwrap() { + KeyboardMode::Map | KeyboardMode::Translate => match &evt.union { + Some(key_event::Union::ControlKey(ck)) => { + return *ck == ControlKey::Meta.into(); + } + Some(key_event::Union::Chr(code)) => { + let key = crate::keycode_to_rdev_key(*code); + return key == RdevKey::MetaLeft || key == RdevKey::MetaRight; + } + _ => {} + }, + KeyboardMode::Legacy => match &evt.union { + Some(key_event::Union::ControlKey(ck)) => { + return *ck == ControlKey::Meta.into(); + } + _ => {} + }, + _ => {} + } + false +} + pub fn handle_key_(evt: &KeyEvent) { if EXITING.load(Ordering::SeqCst) { return; @@ -1381,8 +1410,8 @@ pub fn handle_key_(evt: &KeyEvent) { Some(LockModesHandler::new(&evt)) } _ => { - if evt.down { - Some(LockModesHandler::new(&evt)) + if evt.down && !is_meta_key(evt) { + Some(LockModesHandler::new(evt)) } else { None } From acac3054410a1885593273c18f39b41f46c28124 Mon Sep 17 00:00:00 2001 From: fufesou Date: Wed, 5 Apr 2023 14:30:47 +0800 Subject: [PATCH 2/3] win, linux, single meta key Signed-off-by: fufesou --- src/server/input_service.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/server/input_service.rs b/src/server/input_service.rs index fb04107ca..7ea12c965 100644 --- a/src/server/input_service.rs +++ b/src/server/input_service.rs @@ -1371,13 +1371,13 @@ fn simulate_win2win_hotkey(code: u32, down: bool) { allow_err!(rdev::simulate_code(Some(keycode), None, down)); } -#[cfg(any(target_os = "android", target_os = "ios"))] -fn is_meta_key(_evt: &KeyEvent) -> bool { +#[cfg(not(any(target_os = "windows", target_os = "linux")))] +fn is_win_linux_meta_key(_evt: &KeyEvent) -> bool { false } -#[cfg(not(any(target_os = "android", target_os = "ios")))] -fn is_meta_key(evt: &KeyEvent) -> bool { +#[cfg(any(target_os = "windows", target_os = "linux"))] +fn is_win_linux_meta_key(evt: &KeyEvent) -> bool { match evt.mode.unwrap() { KeyboardMode::Map | KeyboardMode::Translate => match &evt.union { Some(key_event::Union::ControlKey(ck)) => { @@ -1410,7 +1410,7 @@ pub fn handle_key_(evt: &KeyEvent) { Some(LockModesHandler::new(&evt)) } _ => { - if evt.down && !is_meta_key(evt) { + if evt.down && !is_win_linux_meta_key(evt) { Some(LockModesHandler::new(evt)) } else { None From d279588a64589bce9e5a364cf2003f32036f81f6 Mon Sep 17 00:00:00 2001 From: fufesou Date: Wed, 5 Apr 2023 14:54:23 +0800 Subject: [PATCH 3/3] fix build Signed-off-by: fufesou --- src/lib.rs | 1 + src/server/input_service.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index a702e5f11..45b4c63f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ /// cbindgen:ignore pub mod platform; mod keyboard; +#[cfg(not(any(target_os = "android", target_os = "ios")))] pub use keyboard::keycode_to_rdev_key; #[cfg(not(any(target_os = "android", target_os = "ios")))] pub use platform::{get_cursor, get_cursor_data, get_cursor_pos, start_os_service}; diff --git a/src/server/input_service.rs b/src/server/input_service.rs index 7ea12c965..5fb63a597 100644 --- a/src/server/input_service.rs +++ b/src/server/input_service.rs @@ -1410,6 +1410,9 @@ pub fn handle_key_(evt: &KeyEvent) { Some(LockModesHandler::new(&evt)) } _ => { + // LockModesHandler should not be created when single meta is pressing and releasing. + // Because the drop function may insert "CapsLock Click" and "NumLock Click", which breaks single meta click. + // https://github.com/rustdesk/rustdesk/issues/3928#issuecomment-1496936687 if evt.down && !is_win_linux_meta_key(evt) { Some(LockModesHandler::new(evt)) } else {