mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
Supports Mac OS simulate input by scancode
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use core_graphics;
|
||||
|
||||
use rdev::{simulate, EventType, EventType::*, Key as RdevKey, SimulateError};
|
||||
// TODO(dustin): use only the things i need
|
||||
|
||||
use self::core_graphics::display::*;
|
||||
@@ -354,6 +354,11 @@ impl KeyboardControllable for Enigo {
|
||||
}
|
||||
|
||||
fn key_down(&mut self, key: Key) -> crate::ResultType {
|
||||
let keyboard_mode = 1;
|
||||
if keyboard_mode == 1 {
|
||||
self.send_rdev(&key, true);
|
||||
return Ok(());
|
||||
};
|
||||
let code = self.key_to_keycode(key);
|
||||
if code == u16::MAX {
|
||||
return Err("".into());
|
||||
@@ -369,6 +374,11 @@ impl KeyboardControllable for Enigo {
|
||||
}
|
||||
|
||||
fn key_up(&mut self, key: Key) {
|
||||
let keyboard_mode = 1;
|
||||
if keyboard_mode == 1 {
|
||||
self.send_rdev(&key, true);
|
||||
return Ok(());
|
||||
};
|
||||
if let Some(src) = self.event_source.as_ref() {
|
||||
if let Ok(event) =
|
||||
CGEvent::new_keyboard_event(src.clone(), self.key_to_keycode(key), false)
|
||||
@@ -421,6 +431,29 @@ impl Enigo {
|
||||
(x, (display_height as i32) - y_inv)
|
||||
}
|
||||
|
||||
fn send_rdev(&mut self, key: &Key, is_press: bool) -> bool {
|
||||
log::info!("{:?} {:?}", key, is_press);
|
||||
|
||||
if let Key::Raw(keycode) = key {
|
||||
let event_type = match is_press {
|
||||
// todo: Acccodding to client type
|
||||
true => Box::leak(Box::new(EventType::KeyPress(RdevKey::Unknown(
|
||||
(*keycode).into(),
|
||||
)))),
|
||||
false => Box::leak(Box::new(EventType::KeyRelease(RdevKey::Unknown(
|
||||
(*keycode).into(),
|
||||
)))),
|
||||
};
|
||||
|
||||
match simulate(event_type) {
|
||||
Ok(()) => true,
|
||||
Err(SimulateError) => false,
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn key_to_keycode(&mut self, key: Key) -> CGKeyCode {
|
||||
#[allow(deprecated)]
|
||||
// I mean duh, we still need to support deprecated keys until they're removed
|
||||
|
||||
Reference in New Issue
Block a user