Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

log key-up and text injection failures (#16455)

fufesou25d2c6db5508
diff --git a/Cargo.lock b/Cargo.lock
index 727ef11d7..a5fd3560a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6772,7 +6772,7 @@ dependencies = [
[[package]]
name = "rdev"
version = "0.5.0-2"
-source = "git+https://github.com/rustdesk-org/rdev#a361d86a8b0245f3618a9efb375c149530a6b599"
+source = "git+https://github.com/rustdesk-org/rdev#0904f23ce496e255461a98848b85c11fa5a62eab"
dependencies = [
"cocoa 0.24.1",
"core-foundation 0.9.4",
diff --git a/libs/enigo/src/macos/macos_impl.rs b/libs/enigo/src/macos/macos_impl.rs
index 20f5d0cbf..0f1436aec 100644
--- a/libs/enigo/src/macos/macos_impl.rs
+++ b/libs/enigo/src/macos/macos_impl.rs
@@ -36,6 +36,7 @@ const kUCKeyActionDisplay: u16 = 3;
#[allow(non_upper_case_globals)]
const kUCKeyTranslateDeadKeysBit: OptionBits = 1 << 31;
const BUF_LEN: usize = 4;
+const KEYBOARD_ERROR_LOG_INTERVAL: std::time::Duration = std::time::Duration::from_secs(5);
const MOUSE_EVENT_BUTTON_NUMBER_BACK: i64 = 3;
const MOUSE_EVENT_BUTTON_NUMBER_FORWARD: i64 = 4;
@@ -428,7 +429,19 @@ impl KeyboardControllable for Enigo {
if let Ok(event) = CGEvent::new_keyboard_event(src.clone(), 0, true) {
event.set_string(cluster);
self.post(event, None);
+ } else {
+ hbb_common::throttled_log!(
+ KEYBOARD_ERROR_LOG_INTERVAL,
+ error,
+ "Failed to inject macOS Enigo key-sequence: could not create keyboard event"
+ );
}
+ } else {
+ hbb_common::throttled_log!(
+ KEYBOARD_ERROR_LOG_INTERVAL,
+ error,
+ "Failed to inject macOS Enigo key-sequence: event source is not initialized"
+ );
}
}
}
@@ -436,17 +449,40 @@ impl KeyboardControllable for Enigo {
fn key_click(&mut self, key: Key) {
let keycode = self.key_to_keycode(key);
if keycode == u16::MAX {
+ hbb_common::throttled_log!(
+ KEYBOARD_ERROR_LOG_INTERVAL,
+ error,
+ "Failed to inject macOS Enigo key-click: keycode mapping is unavailable"
+ );
return;
}
if let Some(src) = self.event_source.as_ref() {
if let Ok(event) = CGEvent::new_keyboard_event(src.clone(), keycode, true) {
self.post(event, Some(keycode));
+ } else {
+ hbb_common::throttled_log!(
+ KEYBOARD_ERROR_LOG_INTERVAL,
+ error,
+ "Failed to inject macOS Enigo key-down in key-click: could not create keyboard event"
+ );
}
if let Ok(event) = CGEvent::new_keyboard_event(src.clone(), keycode, false) {
self.post(event, Some(keycode));
+ } else {
+ hbb_common::throttled_log!(
+ KEYBOARD_ERROR_LOG_INTERVAL,
+ error,
+ "Failed to inject macOS Enigo key-up in key-click: could not create keyboard event"
+ );
}
+ } else {
+ hbb_common::throttled_log!(
+ KEYBOARD_ERROR_LOG_INTERVAL,
+ error,
+ "Failed to inject macOS Enigo key-click: event source is not initialized"
+ );
}
}
@@ -465,10 +501,29 @@ impl KeyboardControllable for Enigo {
fn key_up(&mut self, key: Key) {
let code = self.key_to_keycode(key);
+ if code == u16::MAX {
+ hbb_common::throttled_log!(
+ KEYBOARD_ERROR_LOG_INTERVAL,
+ error,
+ "Cannot map macOS Enigo key-up to a keycode"
+ );
+ }
if let Some(src) = self.event_source.as_ref() {
if let Ok(event) = CGEvent::new_keyboard_event(src.clone(), code, false) {
self.post(event, Some(code));
+ } else {
+ hbb_common::throttled_log!(
+ KEYBOARD_ERROR_LOG_INTERVAL,
+ error,
+ "Failed to inject macOS Enigo key-up: could not create keyboard event"
+ );
}
+ } else {
+ hbb_common::throttled_log!(
+ KEYBOARD_ERROR_LOG_INTERVAL,
+ error,
+ "Failed to inject macOS Enigo key-up: event source is not initialized"
+ );
}
}
diff --git a/src/server/input_service.rs b/src/server/input_service.rs
index 515e0eb50..5214214e6 100644
--- a/src/server/input_service.rs
+++ b/src/server/input_service.rs
@@ -710,6 +710,8 @@ struct VirtualInputState {
#[cfg(target_os = "macos")]
impl VirtualInputState {
+ const KEY_UP_ERROR_LOG_INTERVAL: Duration = Duration::from_secs(5);
+
fn new() -> Option<Self> {
VirtualInput::new(
CGEventSourceStateID::CombinedSessionState,
@@ -1657,6 +1659,12 @@ fn simulate_(event_type: &EventType) {
let _lock = VIRTUAL_INPUT_MTX.lock();
if let Some(input) = VIRTUAL_INPUT_STATE.as_ref() {
let _ = input.simulate(&event_type);
+ } else if matches!(event_type, EventType::KeyRelease(_)) {
+ hbb_common::throttled_log!(
+ VirtualInputState::KEY_UP_ERROR_LOG_INTERVAL,
+ error,
+ "Failed to inject macOS key-up: virtual input is not initialized"
+ );
}
}
}