diff --git a/src/server/input_service.rs b/src/server/input_service.rs index 3189520be0a..c7f651e9ac7 100644 --- a/src/server/input_service.rs +++ b/src/server/input_service.rs @@ -456,13 +456,22 @@ static RECORD_CURSOR_POS_RUNNING: AtomicBool = AtomicBool::new(false); // https://github.com/rustdesk/rustdesk/issues/9729 // We need to do some special handling for macOS when using the legacy mode. #[cfg(target_os = "macos")] -static LAST_KEY_LEGACY_MODE: AtomicBool = AtomicBool::new(false); -// We use enigo to simulate mouse events. Only the legacy mode uses the key flags. +static LAST_KEY_LEGACY_MODE: AtomicBool = AtomicBool::new(true); +// We use enigo to +// 1. Simulate mouse events +// 2. Simulate the legacy mode key events +// 3. Simulate the functioin key events, like LockScreen #[inline] #[cfg(target_os = "macos")] fn enigo_ignore_flags() -> bool { !LAST_KEY_LEGACY_MODE.load(Ordering::SeqCst) } +#[inline] +#[cfg(target_os = "macos")] +fn set_last_legacy_mode(v: bool) { + LAST_KEY_LEGACY_MODE.store(v, Ordering::SeqCst); + ENIGO.lock().unwrap().set_ignore_flags(!v); +} pub fn try_start_record_cursor_pos() -> Option> { if RECORD_CURSOR_POS_RUNNING.load(Ordering::SeqCst) { @@ -1698,17 +1707,19 @@ pub fn handle_key_(evt: &KeyEvent) { match evt.mode.enum_value() { Ok(KeyboardMode::Map) => { #[cfg(target_os = "macos")] - LAST_KEY_LEGACY_MODE.store(false, Ordering::SeqCst); + set_last_legacy_mode(false); map_keyboard_mode(evt); } Ok(KeyboardMode::Translate) => { #[cfg(target_os = "macos")] - LAST_KEY_LEGACY_MODE.store(false, Ordering::SeqCst); + set_last_legacy_mode(false); translate_keyboard_mode(evt); } _ => { + // All key down events are started from here, + // so we can reset the flag of last legacy mode here. #[cfg(target_os = "macos")] - LAST_KEY_LEGACY_MODE.store(true, Ordering::SeqCst); + set_last_legacy_mode(true); legacy_keyboard_mode(evt); } }