From ffcbc2abaa92485fe674edd36cc4d11a3809551d Mon Sep 17 00:00:00 2001 From: rustdesk Date: Tue, 1 Jun 2021 13:05:04 +0800 Subject: [PATCH] more for right key --- src/server/input_service.rs | 17 +++++++++++++++-- src/ui/remote.rs | 20 ++++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/server/input_service.rs b/src/server/input_service.rs index 957a01653..879a7dea3 100644 --- a/src/server/input_service.rs +++ b/src/server/input_service.rs @@ -186,6 +186,19 @@ fn modifier_sleep() { std::thread::sleep(std::time::Duration::from_nanos(1)); } +#[cfg(not(target_os = "macos"))] +#[inline] +fn get_modifier_state(key: enigo::Key, en: &mut Enigo) -> bool { + let x = en.get_key_state(key.clone()); + match key { + enigo::Key::Shift => x || en.get_key_state(enigo::Key::RightShift), + enigo::Key::Control => x || en.get_key_state(enigo::Key::RightControl), + enigo::Key::Alt => x || en.get_key_state(enigo::Key::RightAlt), + enigo::Key::Meta => x || en.get_key_state(enigo::Key::RWin), + _ => x, + } +} + pub fn handle_mouse(evt: &MouseEvent, conn: i32) { #[cfg(target_os = "macos")] if !*IS_SERVER { @@ -220,7 +233,7 @@ fn handle_mouse_(evt: &MouseEvent, conn: i32) { en.add_flag(key); #[cfg(not(target_os = "macos"))] if key != &enigo::Key::CapsLock && key != &enigo::Key::NumLock { - if !en.get_key_state(key.clone()) { + if !get_modifier_state(key.clone(), &mut en) { en.key_down(key.clone()).ok(); modifier_sleep(); to_release.push(key); @@ -428,7 +441,7 @@ fn handle_key_(evt: &KeyEvent) { has_numlock = true; } } else { - if !en.get_key_state(key.clone()) { + if !get_modifier_state(key.clone(), &mut en) { en.key_down(key.clone()).ok(); modifier_sleep(); to_release.push(key); diff --git a/src/ui/remote.rs b/src/ui/remote.rs index 0af34704d..17e6c8af1 100644 --- a/src/ui/remote.rs +++ b/src/ui/remote.rs @@ -899,16 +899,28 @@ impl Handler { } } */ - if alt && !crate::is_control_key(&key_event, &ControlKey::Alt) { + if alt + && !crate::is_control_key(&key_event, &ControlKey::Alt) + && !crate::is_control_key(&key_event, &ControlKey::RAlt) + { key_event.modifiers.push(ControlKey::Alt.into()); } - if shift && !crate::is_control_key(&key_event, &ControlKey::Shift) { + if shift + && !crate::is_control_key(&key_event, &ControlKey::Shift) + && !crate::is_control_key(&key_event, &ControlKey::RShift) + { key_event.modifiers.push(ControlKey::Shift.into()); } - if ctrl && !crate::is_control_key(&key_event, &ControlKey::Control) { + if ctrl + && !crate::is_control_key(&key_event, &ControlKey::Control) + && !crate::is_control_key(&key_event, &ControlKey::RControl) + { key_event.modifiers.push(ControlKey::Control.into()); } - if command && !crate::is_control_key(&key_event, &ControlKey::Meta) { + if command + && !crate::is_control_key(&key_event, &ControlKey::Meta) + && !crate::is_control_key(&key_event, &ControlKey::RWin) + { key_event.modifiers.push(ControlKey::Meta.into()); } if crate::is_control_key(&key_event, &ControlKey::CapsLock) {