mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-12-02 18:59:24 +08:00
Sync Caps status
This commit is contained in:
parent
7ae065739c
commit
828795b437
@ -579,20 +579,46 @@ pub fn handle_key(evt: &KeyEvent) {
|
||||
handle_key_(evt);
|
||||
}
|
||||
|
||||
fn map_keyboard_map(evt: &KeyEvent) {
|
||||
// map mode(1): Send keycode according to the peer platform.
|
||||
let event_type = match evt.down {
|
||||
true => EventType::KeyPress(RdevKey::Unknown(evt.get_chr())),
|
||||
false => EventType::KeyRelease(RdevKey::Unknown(evt.get_chr())),
|
||||
};
|
||||
|
||||
match simulate(&event_type) {
|
||||
fn rdev_simulate(event_type: &EventType) {
|
||||
let delay = std::time::Duration::from_millis(20);
|
||||
match simulate(event_type) {
|
||||
Ok(()) => (),
|
||||
Err(_simulate_error) => {
|
||||
// todo
|
||||
log::error!("rdev could not send {:?}", event_type);
|
||||
}
|
||||
}
|
||||
// Let ths OS catchup (at least MacOS)
|
||||
std::thread::sleep(delay);
|
||||
}
|
||||
|
||||
fn map_keyboard_map(evt: &KeyEvent) {
|
||||
// map mode(1): Send keycode according to the peer platform.
|
||||
let mut en = ENIGO.lock().unwrap();
|
||||
// sync CAPS status
|
||||
let caps_locking = evt
|
||||
.modifiers
|
||||
.iter()
|
||||
.position(|&r| r == ControlKey::CapsLock.into())
|
||||
.is_some();
|
||||
println!("[*] remote, client: {:?} {:?}", caps_locking, en.get_key_state(enigo::Key::CapsLock));
|
||||
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));
|
||||
}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 {
|
||||
true => EventType::KeyPress(RdevKey::Unknown(evt.get_chr())),
|
||||
false => EventType::KeyRelease(RdevKey::Unknown(evt.get_chr())),
|
||||
};
|
||||
|
||||
rdev_simulate(&event_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -791,8 +817,10 @@ mod test {
|
||||
});
|
||||
// set key/char base on char
|
||||
let mut evt = KeyEvent::new();
|
||||
evt.set_chr(49);
|
||||
evt.mode = 3;
|
||||
evt.set_chr(66);
|
||||
evt.mode = 1;
|
||||
|
||||
evt.modifiers.push(ControlKey::CapsLock.into());
|
||||
|
||||
// press
|
||||
evt.down = true;
|
||||
|
@ -984,6 +984,11 @@ impl Handler {
|
||||
} else {
|
||||
key_event.down = false;
|
||||
}
|
||||
|
||||
if get_key_state(enigo::Key::CapsLock) {
|
||||
key_event.modifiers.push(ControlKey::CapsLock.into());
|
||||
}
|
||||
|
||||
self.send_key_event(key_event, 1);
|
||||
}
|
||||
|
||||
@ -1236,7 +1241,7 @@ impl Handler {
|
||||
key_event.down = true;
|
||||
}
|
||||
dbg!(&key_event);
|
||||
self.send_key_event(key_event, 2)
|
||||
self.send_key_event(key_event, 3)
|
||||
}
|
||||
|
||||
fn key_down_or_up(&mut self, down_or_up: bool, key: RdevKey, evt: Event) {
|
||||
|
Loading…
Reference in New Issue
Block a user