File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -457,7 +457,7 @@ static RECORD_CURSOR_POS_RUNNING: AtomicBool = AtomicBool::new(false);
457457// We need to do some special handling for macOS when using the legacy mode.
458458#[ cfg( target_os = "macos" ) ]
459459static LAST_KEY_LEGACY_MODE : AtomicBool = AtomicBool :: new ( true ) ;
460- // We use enigo to
460+ // We use enigo to
461461// 1. Simulate mouse events
462462// 2. Simulate the legacy mode key events
463463// 3. Simulate the functioin key events, like LockScreen
@@ -667,7 +667,17 @@ fn is_pressed(key: &Key, en: &mut Enigo) -> bool {
667667#[ inline]
668668#[ cfg( target_os = "macos" ) ]
669669fn key_sleep ( ) {
670- std:: thread:: sleep ( Duration :: from_millis ( 20 ) ) ;
670+ // https://www.reddit.com/r/rustdesk/comments/1kn1w5x/typing_lags_when_connecting_to_macos_clients/
671+ //
672+ // There's a strange bug when running by `launchctl load -w /Library/LaunchAgents/abc.plist`
673+ // `std::thread::sleep(Duration::from_millis(20));` may sleep 90ms or more.
674+ // Though `/Applications/RustDesk.app/Contents/MacOS/rustdesk --server` in terminal is ok.
675+ let now = Instant :: now ( ) ;
676+ // This workaround results `21~24ms` sleep time in my tests.
677+ // But it works well in my tests.
678+ while now. elapsed ( ) < Duration :: from_millis ( 12 ) {
679+ std:: thread:: sleep ( Duration :: from_millis ( 1 ) ) ;
680+ }
671681}
672682
673683#[ inline]
You can’t perform that action at this time.
0 commit comments