Get key state by read file
This commit is contained in:
parent
5dfd041d8f
commit
a105aff2aa
@ -155,18 +155,6 @@ impl Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(x) => {
|
Ok(x) => {
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
if !*crate::common::IS_X11.lock().unwrap() {
|
|
||||||
let keyboard = super::uinput::client::UInputKeyboard::new().await?;
|
|
||||||
log::info!("UInput keyboard created");
|
|
||||||
let mouse = super::uinput::client::UInputMouse::new().await?;
|
|
||||||
log::info!("UInput mouse created");
|
|
||||||
|
|
||||||
let mut en = ENIGO.lock().unwrap();
|
|
||||||
en.set_uinput_keyboard(Some(Box::new(keyboard)));
|
|
||||||
en.set_uinput_mouse(Some(Box::new(mouse)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(x)},
|
Ok(x)},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -665,7 +665,7 @@ fn map_keyboard_mode(evt: &KeyEvent) {
|
|||||||
en.key_down(enigo::Key::CapsLock);
|
en.key_down(enigo::Key::CapsLock);
|
||||||
|
|
||||||
if evt.down {
|
if evt.down {
|
||||||
en.key_down(enigo::Key::Raw(code));
|
en.key_down(enigo::Key::Raw(code)).ok();
|
||||||
} else {
|
} else {
|
||||||
en.key_up(enigo::Key::Raw(code));
|
en.key_up(enigo::Key::Raw(code));
|
||||||
}
|
}
|
||||||
@ -871,7 +871,7 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
|
|||||||
if *IS_X11.lock().unwrap() {
|
if *IS_X11.lock().unwrap() {
|
||||||
tfc_key_down_or_up(key.clone(), true, false);
|
tfc_key_down_or_up(key.clone(), true, false);
|
||||||
} else {
|
} else {
|
||||||
allow_err!(en.key_down(key.clone()));
|
en.key_down(key.clone()).ok();
|
||||||
}
|
}
|
||||||
KEYS_DOWN
|
KEYS_DOWN
|
||||||
.lock()
|
.lock()
|
||||||
|
@ -8,7 +8,7 @@ use crate::client::{
|
|||||||
};
|
};
|
||||||
use crate::{client::Data, client::Interface};
|
use crate::{client::Data, client::Interface};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use std::io::Read;
|
||||||
use hbb_common::config::{Config, LocalConfig, PeerConfig};
|
use hbb_common::config::{Config, LocalConfig, PeerConfig};
|
||||||
use hbb_common::rendezvous_proto::ConnType;
|
use hbb_common::rendezvous_proto::ConnType;
|
||||||
use hbb_common::tokio::{self, sync::mpsc};
|
use hbb_common::tokio::{self, sync::mpsc};
|
||||||
@ -416,10 +416,20 @@ impl<T: InvokeUi> Session<T> {
|
|||||||
{
|
{
|
||||||
key_event.modifiers.push(ControlKey::Meta.into());
|
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) {
|
if get_key_state(enigo::Key::CapsLock) {
|
||||||
key_event.modifiers.push(ControlKey::CapsLock.into());
|
key_event.modifiers.push(ControlKey::CapsLock.into());
|
||||||
}
|
}
|
||||||
if self.peer_platform() != "Mac OS" {
|
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) {
|
if get_key_state(enigo::Key::NumLock) {
|
||||||
key_event.modifiers.push(ControlKey::NumLock.into());
|
key_event.modifiers.push(ControlKey::NumLock.into());
|
||||||
}
|
}
|
||||||
@ -1362,3 +1372,28 @@ 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 });
|
let body = serde_json::json!({ "id": id, "Id": conn_id, "note": note });
|
||||||
allow_err!(crate::post_request(url, body.to_string(), "").await);
|
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::<i32>().unwrap_or(0);
|
||||||
|
status
|
||||||
|
}else{
|
||||||
|
0
|
||||||
|
};
|
||||||
|
log::info!("get led state: {}", status);
|
||||||
|
status == 1
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user