mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-07 22:58:04 +08:00
refactor: sync status of caps and numlock
This commit is contained in:
parent
176ed43807
commit
a98174448f
@ -6,6 +6,7 @@ use dispatch::Queue;
|
|||||||
use enigo::{Enigo, Key, KeyboardControllable, MouseButton, MouseControllable};
|
use enigo::{Enigo, Key, KeyboardControllable, MouseButton, MouseControllable};
|
||||||
use hbb_common::{config::COMPRESS_LEVEL, get_time, protobuf::EnumOrUnknown};
|
use hbb_common::{config::COMPRESS_LEVEL, get_time, protobuf::EnumOrUnknown};
|
||||||
use rdev::{simulate, EventType, Key as RdevKey};
|
use rdev::{simulate, EventType, Key as RdevKey};
|
||||||
|
use std::time::Duration;
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryFrom,
|
convert::TryFrom,
|
||||||
ops::Sub,
|
ops::Sub,
|
||||||
@ -753,15 +754,14 @@ fn rdev_key_down_or_up(key: RdevKey, down_or_up: bool) {
|
|||||||
true => EventType::KeyPress(key),
|
true => EventType::KeyPress(key),
|
||||||
false => EventType::KeyRelease(key),
|
false => EventType::KeyRelease(key),
|
||||||
};
|
};
|
||||||
let delay = std::time::Duration::from_millis(20);
|
|
||||||
match simulate(&event_type) {
|
match simulate(&event_type) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(_simulate_error) => {
|
Err(_simulate_error) => {
|
||||||
log::error!("Could not send {:?}", &event_type);
|
log::error!("Could not send {:?}", &event_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Let ths OS catchup (at least MacOS)
|
#[cfg(target_os = "macos")]
|
||||||
std::thread::sleep(delay);
|
std::thread::sleep(Duration::from_millis(20));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rdev_key_click(key: RdevKey) {
|
fn rdev_key_click(key: RdevKey) {
|
||||||
@ -769,8 +769,7 @@ fn rdev_key_click(key: RdevKey) {
|
|||||||
rdev_key_down_or_up(key, false);
|
rdev_key_down_or_up(key, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync_status(evt: &KeyEvent) -> (bool, bool) {
|
fn sync_status(evt: &KeyEvent) {
|
||||||
/* todo! Shift+delete */
|
|
||||||
let mut en = ENIGO.lock().unwrap();
|
let mut en = ENIGO.lock().unwrap();
|
||||||
|
|
||||||
// remote caps status
|
// remote caps status
|
||||||
@ -808,7 +807,18 @@ fn sync_status(evt: &KeyEvent) -> (bool, bool) {
|
|||||||
_ => click_numlock,
|
_ => click_numlock,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return (click_capslock, click_numlock);
|
|
||||||
|
if click_capslock {
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
en.key_click(enigo::Key::CapsLock);
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
en.key_down(enigo::Key::CapsLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
if click_numlock {
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
en.key_click(enigo::Key::NumLock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_keyboard_mode(evt: &KeyEvent) {
|
fn map_keyboard_mode(evt: &KeyEvent) {
|
||||||
@ -816,25 +826,12 @@ fn map_keyboard_mode(evt: &KeyEvent) {
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
crate::platform::windows::try_change_desktop();
|
crate::platform::windows::try_change_desktop();
|
||||||
|
|
||||||
let (click_capslock, click_numlock) = sync_status(evt);
|
|
||||||
|
|
||||||
// Wayland
|
// Wayland
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
if !*IS_X11.lock().unwrap() {
|
if !*IS_X11.lock().unwrap() {
|
||||||
let mut en = ENIGO.lock().unwrap();
|
let mut en = ENIGO.lock().unwrap();
|
||||||
let code = evt.chr() as u16;
|
let code = evt.chr() as u16;
|
||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
if click_capslock {
|
|
||||||
en.key_click(enigo::Key::CapsLock);
|
|
||||||
}
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
if click_numlock {
|
|
||||||
en.key_click(enigo::Key::NumLock);
|
|
||||||
}
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
en.key_down(enigo::Key::CapsLock);
|
|
||||||
|
|
||||||
if evt.down {
|
if evt.down {
|
||||||
en.key_down(enigo::Key::Raw(code)).ok();
|
en.key_down(enigo::Key::Raw(code)).ok();
|
||||||
} else {
|
} else {
|
||||||
@ -843,35 +840,14 @@ fn map_keyboard_mode(evt: &KeyEvent) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
if click_capslock {
|
|
||||||
rdev_key_click(RdevKey::CapsLock);
|
|
||||||
}
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
if click_numlock {
|
|
||||||
rdev_key_click(RdevKey::NumLock);
|
|
||||||
}
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
if evt.down && click_capslock {
|
|
||||||
rdev_key_down_or_up(RdevKey::CapsLock, evt.down);
|
|
||||||
}
|
|
||||||
|
|
||||||
rdev_key_down_or_up(RdevKey::Unknown(evt.chr()), evt.down);
|
rdev_key_down_or_up(RdevKey::Unknown(evt.chr()), evt.down);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn legacy_keyboard_mode(evt: &KeyEvent) {
|
fn legacy_keyboard_mode(evt: &KeyEvent) {
|
||||||
let (click_capslock, click_numlock) = sync_status(evt);
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
crate::platform::windows::try_change_desktop();
|
crate::platform::windows::try_change_desktop();
|
||||||
let mut en = ENIGO.lock().unwrap();
|
let mut en = ENIGO.lock().unwrap();
|
||||||
if click_capslock {
|
|
||||||
en.key_click(Key::CapsLock);
|
|
||||||
}
|
|
||||||
if click_numlock {
|
|
||||||
en.key_click(Key::NumLock);
|
|
||||||
}
|
|
||||||
// disable numlock if press home etc when numlock is on,
|
// disable numlock if press home etc when numlock is on,
|
||||||
// because we will get numpad value (7,8,9 etc) if not
|
// because we will get numpad value (7,8,9 etc) if not
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
@ -1001,6 +977,9 @@ pub fn handle_key_(evt: &KeyEvent) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if evt.down {
|
||||||
|
sync_status(evt)
|
||||||
|
}
|
||||||
match evt.mode.unwrap() {
|
match evt.mode.unwrap() {
|
||||||
KeyboardMode::Map => {
|
KeyboardMode::Map => {
|
||||||
map_keyboard_mode(evt);
|
map_keyboard_mode(evt);
|
||||||
|
Loading…
Reference in New Issue
Block a user