revert keysym back, enigo's Layout can do this

This commit is contained in:
rustdesk 2022-01-09 21:05:00 +08:00
parent a0c704f36e
commit 3f56c82c7b
6 changed files with 10 additions and 45 deletions

View File

@ -418,8 +418,6 @@ pub enum Key {
Layout(char), Layout(char),
/// raw keycode eg 0x38 /// raw keycode eg 0x38
Raw(u16), Raw(u16),
/// VNC keysym
KeySym(u32),
} }
/// Representing an interface and a set of keyboard functions every /// Representing an interface and a set of keyboard functions every

View File

@ -181,9 +181,6 @@ impl MouseControllable for Enigo {
} }
} }
fn keysequence<'a>(key: Key) -> Cow<'a, str> { fn keysequence<'a>(key: Key) -> Cow<'a, str> {
if let Key::KeySym(sym) = key {
return Cow::Owned("".to_owned());
}
if let Key::Layout(c) = key { if let Key::Layout(c) = key {
return Cow::Owned(format!("U{:X}", c as u32)); return Cow::Owned(format!("U{:X}", c as u32));
} }

View File

@ -426,7 +426,6 @@ impl Enigo {
Key::Raw(raw_keycode) => raw_keycode, Key::Raw(raw_keycode) => raw_keycode,
Key::Layout(c) => self.map_key_board(c), Key::Layout(c) => self.map_key_board(c),
Key::KeySym(sym) => 0 as _,
Key::Super | Key::Command | Key::Windows | Key::Meta => kVK_Command, Key::Super | Key::Command | Key::Windows | Key::Meta => kVK_Command,
_ => 0, _ => 0,

View File

@ -340,7 +340,6 @@ impl Enigo {
Key::Raw(raw_keycode) => raw_keycode, Key::Raw(raw_keycode) => raw_keycode,
Key::Layout(c) => self.get_layoutdependent_keycode(c.to_string()), Key::Layout(c) => self.get_layoutdependent_keycode(c.to_string()),
Key::Super | Key::Command | Key::Windows | Key::Meta => EVK_LWIN, Key::Super | Key::Command | Key::Windows | Key::Meta => EVK_LWIN,
Key::KeySym(sym) => 0,
} }
} }

View File

@ -173,7 +173,6 @@ message KeyEvent {
uint32 chr = 4; uint32 chr = 4;
uint32 unicode = 5; uint32 unicode = 5;
string seq = 6; string seq = 6;
uint32 keysym = 7;
} }
repeated ControlKey modifiers = 8; repeated ControlKey modifiers = 8;
} }

View File

@ -40,8 +40,7 @@ struct Input {
time: i64, time: i64,
} }
const KEY_CHAR_START: u64 = 0xFFFF; const KEY_CHAR_START: i32 = 9999;
const KEY_SYM_START: u64 = 0xFFFFFFFF;
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct MouseCursorSub { pub struct MouseCursorSub {
@ -164,7 +163,7 @@ fn run_cursor(sp: MouseCursorService, state: &mut StateCursor) -> ResultType<()>
lazy_static::lazy_static! { lazy_static::lazy_static! {
static ref ENIGO: Arc<Mutex<Enigo>> = Arc::new(Mutex::new(Enigo::new())); static ref ENIGO: Arc<Mutex<Enigo>> = Arc::new(Mutex::new(Enigo::new()));
static ref KEYS_DOWN: Arc<Mutex<HashMap<u64, Instant>>> = Default::default(); static ref KEYS_DOWN: Arc<Mutex<HashMap<i32, Instant>>> = Default::default();
static ref LATEST_INPUT: Arc<Mutex<Input>> = Default::default(); static ref LATEST_INPUT: Arc<Mutex<Input>> = Default::default();
} }
static EXITING: AtomicBool = AtomicBool::new(false); static EXITING: AtomicBool = AtomicBool::new(false);
@ -257,15 +256,13 @@ fn fix_key_down_timeout(force: bool) {
if force || value.elapsed().as_millis() >= 3_000 { if force || value.elapsed().as_millis() >= 3_000 {
KEYS_DOWN.lock().unwrap().remove(&key); KEYS_DOWN.lock().unwrap().remove(&key);
let key = if key < KEY_CHAR_START { let key = if key < KEY_CHAR_START {
if let Some(key) = KEY_MAP.get(&(key as _)) { if let Some(key) = KEY_MAP.get(&key) {
Some(*key) Some(*key)
} else { } else {
None None
} }
} else if key < KEY_SYM_START {
Some(Key::Layout(((key - KEY_CHAR_START) as u8) as _))
} else { } else {
Some(Key::KeySym((key - KEY_SYM_START) as u32)) Some(Key::Layout(((key - KEY_CHAR_START) as u8) as _))
}; };
if let Some(key) = key { if let Some(key) = key {
let func = move || { let func = move || {
@ -355,10 +352,7 @@ fn handle_mouse_(evt: &MouseEvent, conn: i32) {
modifier_sleep(); modifier_sleep();
to_release.push(key); to_release.push(key);
} else { } else {
KEYS_DOWN KEYS_DOWN.lock().unwrap().insert(ck.value(), Instant::now());
.lock()
.unwrap()
.insert(ck.value() as _, Instant::now());
} }
} }
} }
@ -578,10 +572,7 @@ fn handle_key_(evt: &KeyEvent) {
modifier_sleep(); modifier_sleep();
to_release.push(key); to_release.push(key);
} else { } else {
KEYS_DOWN KEYS_DOWN.lock().unwrap().insert(ck.value(), Instant::now());
.lock()
.unwrap()
.insert(ck.value() as _, Instant::now());
} }
} }
} }
@ -615,13 +606,10 @@ fn handle_key_(evt: &KeyEvent) {
} }
if evt.down { if evt.down {
allow_err!(en.key_down(key.clone())); allow_err!(en.key_down(key.clone()));
KEYS_DOWN KEYS_DOWN.lock().unwrap().insert(ck.value(), Instant::now());
.lock()
.unwrap()
.insert(ck.value() as _, Instant::now());
} else { } else {
en.key_up(key.clone()); en.key_up(key.clone());
KEYS_DOWN.lock().unwrap().remove(&(ck.value() as _)); KEYS_DOWN.lock().unwrap().remove(&ck.value());
} }
} else if ck.value() == ControlKey::CtrlAltDel.value() { } else if ck.value() == ControlKey::CtrlAltDel.value() {
// have to spawn new thread because send_sas is tokio_main, the caller can not be tokio_main. // have to spawn new thread because send_sas is tokio_main, the caller can not be tokio_main.
@ -639,28 +627,13 @@ fn handle_key_(evt: &KeyEvent) {
KEYS_DOWN KEYS_DOWN
.lock() .lock()
.unwrap() .unwrap()
.insert(chr as u64 + KEY_CHAR_START, Instant::now()); .insert(chr as i32 + KEY_CHAR_START, Instant::now());
} else { } else {
en.key_up(Key::Layout(chr as u8 as _)); en.key_up(Key::Layout(chr as u8 as _));
KEYS_DOWN KEYS_DOWN
.lock() .lock()
.unwrap() .unwrap()
.remove(&(chr as u64 + KEY_CHAR_START)); .remove(&(chr as i32 + KEY_CHAR_START));
}
}
Some(key_event::Union::keysym(sym)) => {
if evt.down {
allow_err!(en.key_down(Key::KeySym(sym)));
KEYS_DOWN
.lock()
.unwrap()
.insert(sym as u64 + KEY_SYM_START, Instant::now());
} else {
en.key_up(Key::KeySym(sym));
KEYS_DOWN
.lock()
.unwrap()
.remove(&(sym as u64 + KEY_SYM_START));
} }
} }
Some(key_event::Union::unicode(chr)) => { Some(key_event::Union::unicode(chr)) => {