diff --git a/libs/enigo/src/linux/nix_impl.rs b/libs/enigo/src/linux/nix_impl.rs index 2e3fb8a24..895479481 100644 --- a/libs/enigo/src/linux/nix_impl.rs +++ b/libs/enigo/src/linux/nix_impl.rs @@ -1,5 +1,6 @@ use super::{xdo::EnigoXdo}; use crate::{Key, KeyboardControllable, MouseButton, MouseControllable}; +use std::io::Read; /// The main struct for handling the event emitting // #[derive(Default)] @@ -111,6 +112,30 @@ impl MouseControllable for Enigo { } } +fn get_led_state(key: Key) -> bool{ + let led_file = match key{ + Key::CapsLock => { + "/sys/class/leds/input1::capslock/brightness" + } + Key::NumLock => { + "/sys/class/leds/input1::numlock/brightness" + } + _ => { + return false; + } + }; + + let status = if let Ok(mut file) = std::fs::File::open(&led_file) { + let mut content = String::new(); + file.read_to_string(&mut content).ok(); + let status = content.trim_end().to_string().parse::().unwrap_or(0); + status + }else{ + 0 + }; + status == 1 +} + impl KeyboardControllable for Enigo { fn get_key_state(&mut self, key: Key) -> bool { if self.is_x11 { @@ -119,7 +144,7 @@ impl KeyboardControllable for Enigo { if let Some(keyboard) = &mut self.uinput_keyboard { keyboard.get_key_state(key) } else { - false + get_led_state(key) } } } diff --git a/src/ui_session_interface.rs b/src/ui_session_interface.rs index 254db238a..d0142333d 100644 --- a/src/ui_session_interface.rs +++ b/src/ui_session_interface.rs @@ -330,7 +330,6 @@ impl Session { if get_key_state(enigo::Key::NumLock) { key_event.modifiers.push(ControlKey::NumLock.into()); } - log::info!("{:?}", get_key_state(enigo::Key::NumLock)); self.send_key_event(key_event, KeyboardMode::Map); } @@ -416,20 +415,11 @@ impl Session { { key_event.modifiers.push(ControlKey::Meta.into()); } - #[cfg(target_os = "linux")] - if get_led_state(enigo::Key::CapsLock){ - key_event.modifiers.push(ControlKey::CapsLock.into()); - } - #[cfg(not(target_os = "linux"))] + if get_key_state(enigo::Key::CapsLock) { key_event.modifiers.push(ControlKey::CapsLock.into()); } if self.peer_platform() != "Mac OS" { - #[cfg(target_os = "linux")] - if get_led_state(enigo::Key::NumLock){ - key_event.modifiers.push(ControlKey::NumLock.into()); - } - #[cfg(not(target_os = "linux"))] if get_key_state(enigo::Key::NumLock) { key_event.modifiers.push(ControlKey::NumLock.into()); } @@ -1371,29 +1361,4 @@ async fn start_one_port_forward( async fn send_note(url: String, id: String, conn_id: i32, note: String) { let body = serde_json::json!({ "id": id, "Id": conn_id, "note": note }); allow_err!(crate::post_request(url, body.to_string(), "").await); -} - -fn get_led_state(key: enigo::Key) -> bool{ - let led_file = match key{ - enigo::Key::CapsLock => { - "/sys/class/leds/input1::capslock/brightness" - } - enigo::Key::NumLock => { - "/sys/class/leds/input1::numlock/brightness" - } - _ => { - return false; - } - }; - - let status = if let Ok(mut file) = std::fs::File::open(&led_file) { - let mut content = String::new(); - file.read_to_string(&mut content).ok(); - let status = content.trim_end().to_string().parse::().unwrap_or(0); - status - }else{ - 0 - }; - log::info!("get led state: {}", status); - status == 1 } \ No newline at end of file