mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-12-12 10:19:09 +08:00
Refactor rdev simulate
This commit is contained in:
parent
828795b437
commit
e0a7238cc1
@ -579,21 +579,23 @@ pub fn handle_key(evt: &KeyEvent) {
|
|||||||
handle_key_(evt);
|
handle_key_(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rdev_simulate(event_type: &EventType) {
|
fn rdev_key_down_or_up(key: RdevKey, down_or_up: bool) {
|
||||||
|
let event_type = match down_or_up {
|
||||||
|
true => EventType::KeyPress(key),
|
||||||
|
false => EventType::KeyRelease(key),
|
||||||
|
};
|
||||||
let delay = std::time::Duration::from_millis(20);
|
let delay = std::time::Duration::from_millis(20);
|
||||||
match simulate(event_type) {
|
match simulate(&event_type) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(_simulate_error) => {
|
Err(_simulate_error) => {
|
||||||
// todo
|
println!("We could not send {:?}", &event_type);
|
||||||
log::error!("rdev could not send {:?}", event_type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Let ths OS catchup (at least MacOS)
|
// Let ths OS catchup (at least MacOS)
|
||||||
std::thread::sleep(delay);
|
std::thread::sleep(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_keyboard_map(evt: &KeyEvent) {
|
fn sync_status(evt: &KeyEvent) {
|
||||||
// map mode(1): Send keycode according to the peer platform.
|
|
||||||
let mut en = ENIGO.lock().unwrap();
|
let mut en = ENIGO.lock().unwrap();
|
||||||
// sync CAPS status
|
// sync CAPS status
|
||||||
let caps_locking = evt
|
let caps_locking = evt
|
||||||
@ -601,24 +603,24 @@ fn map_keyboard_map(evt: &KeyEvent) {
|
|||||||
.iter()
|
.iter()
|
||||||
.position(|&r| r == ControlKey::CapsLock.into())
|
.position(|&r| r == ControlKey::CapsLock.into())
|
||||||
.is_some();
|
.is_some();
|
||||||
println!("[*] remote, client: {:?} {:?}", caps_locking, en.get_key_state(enigo::Key::CapsLock));
|
println!(
|
||||||
if caps_locking && !en.get_key_state(enigo::Key::CapsLock)
|
"[*] remote, client: {:?} {:?}",
|
||||||
|
caps_locking,
|
||||||
|
en.get_key_state(enigo::Key::CapsLock)
|
||||||
|
);
|
||||||
|
if (caps_locking && !en.get_key_state(enigo::Key::CapsLock))
|
||||||
|
|| (!caps_locking && en.get_key_state(enigo::Key::CapsLock))
|
||||||
{
|
{
|
||||||
println!("[*]: Changing status");
|
println!("[*]: Changing status");
|
||||||
rdev_simulate(&EventType::KeyPress(RdevKey::CapsLock));
|
rdev_key_down_or_up(RdevKey::CapsLock, true);
|
||||||
rdev_simulate(&EventType::KeyRelease(RdevKey::CapsLock));
|
rdev_key_down_or_up(RdevKey::CapsLock, false);
|
||||||
}else if !caps_locking && en.get_key_state(enigo::Key::CapsLock){
|
|
||||||
println!("[*]: Changing status");
|
|
||||||
rdev_simulate(&EventType::KeyPress(RdevKey::CapsLock));
|
|
||||||
rdev_simulate(&EventType::KeyRelease(RdevKey::CapsLock));
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let event_type = match evt.down {
|
fn map_keyboard_map(evt: &KeyEvent) {
|
||||||
true => EventType::KeyPress(RdevKey::Unknown(evt.get_chr())),
|
// map mode(1): Send keycode according to the peer platform.
|
||||||
false => EventType::KeyRelease(RdevKey::Unknown(evt.get_chr())),
|
sync_status(evt);
|
||||||
};
|
rdev_key_down_or_up(RdevKey::Unknown(evt.get_chr()), evt.down);
|
||||||
|
|
||||||
rdev_simulate(&event_type);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user