@@ -664,6 +664,8 @@ fn is_pressed(key: &Key, en: &mut Enigo) -> bool {
664664 get_modifier_state ( key. clone ( ) , en)
665665}
666666
667+ // Sleep for 8ms is enough in my tests, but we sleep 12ms to be safe.
668+ // sleep 12ms In my test, the characters are already output in real time.
667669#[ inline]
668670#[ cfg( target_os = "macos" ) ]
669671fn key_sleep ( ) {
@@ -673,8 +675,6 @@ fn key_sleep() {
673675 // `std::thread::sleep(Duration::from_millis(20));` may sleep 90ms or more.
674676 // Though `/Applications/RustDesk.app/Contents/MacOS/rustdesk --server` in terminal is ok.
675677 let now = Instant :: now ( ) ;
676- // This workaround results `21~24ms` sleep time in my tests.
677- // But it works well in my tests.
678678 while now. elapsed ( ) < Duration :: from_millis ( 12 ) {
679679 std:: thread:: sleep ( Duration :: from_millis ( 1 ) ) ;
680680 }
@@ -1201,6 +1201,13 @@ pub fn handle_key(evt: &KeyEvent) {
12011201 // having GUI, run main GUI thread, otherwise crash
12021202 let evt = evt. clone ( ) ;
12031203 QUEUE . exec_async ( move || handle_key_ ( & evt) ) ;
1204+ // Key sleep is required for macOS.
1205+ // If we don't sleep, the key press/release events may not take effect.
1206+ //
1207+ // For example, the controlled side osx `12.7.6` or `15.1.1`
1208+ // If we input characters quickly and continuously, and press or release "Shift" for a short period of time,
1209+ // it is possible that after releasing "Shift", the controlled side will still print uppercase characters.
1210+ // Though it is not very easy to reproduce.
12041211 key_sleep ( ) ;
12051212}
12061213
0 commit comments