diff --git a/libs/enigo/src/lib.rs b/libs/enigo/src/lib.rs index 893f5918c..10c5da4a7 100644 --- a/libs/enigo/src/lib.rs +++ b/libs/enigo/src/lib.rs @@ -418,6 +418,8 @@ pub enum Key { Layout(char), /// raw keycode eg 0x38 Raw(u16), + /// VNC keysym + KeySym(u32), } /// Representing an interface and a set of keyboard functions every diff --git a/libs/enigo/src/linux.rs b/libs/enigo/src/linux.rs index 24628c1f9..2fe5d2205 100644 --- a/libs/enigo/src/linux.rs +++ b/libs/enigo/src/linux.rs @@ -181,6 +181,9 @@ impl MouseControllable for Enigo { } } fn keysequence<'a>(key: Key) -> Cow<'a, str> { + if let Key::KeySym(sym) = key { + return Cow::Owned(""); + } if let Key::Layout(c) = key { return Cow::Owned(format!("U{:X}", c as u32)); } diff --git a/libs/enigo/src/macos/macos_impl.rs b/libs/enigo/src/macos/macos_impl.rs index 0ee038012..93b78c6d8 100644 --- a/libs/enigo/src/macos/macos_impl.rs +++ b/libs/enigo/src/macos/macos_impl.rs @@ -426,6 +426,7 @@ impl Enigo { Key::Raw(raw_keycode) => raw_keycode, Key::Layout(c) => self.map_key_board(c), + Key::KeySym(sym) => 0 as _, Key::Super | Key::Command | Key::Windows | Key::Meta => kVK_Command, _ => 0, diff --git a/libs/enigo/src/win/win_impl.rs b/libs/enigo/src/win/win_impl.rs index 3a6b6215f..3f83dc951 100644 --- a/libs/enigo/src/win/win_impl.rs +++ b/libs/enigo/src/win/win_impl.rs @@ -340,6 +340,7 @@ impl Enigo { Key::Raw(raw_keycode) => raw_keycode, Key::Layout(c) => self.get_layoutdependent_keycode(c.to_string()), Key::Super | Key::Command | Key::Windows | Key::Meta => EVK_LWIN, + Key::KeySym(sym) => 0, } } diff --git a/libs/hbb_common/protos/message.proto b/libs/hbb_common/protos/message.proto index 24bc189b2..47c526dd1 100644 --- a/libs/hbb_common/protos/message.proto +++ b/libs/hbb_common/protos/message.proto @@ -172,6 +172,7 @@ message KeyEvent { uint32 chr = 4; uint32 unicode = 5; string seq = 6; + uint32 keysym = 7; } repeated ControlKey modifiers = 8; } diff --git a/src/client.rs b/src/client.rs index 29e2585b1..35e4ccdb5 100644 --- a/src/client.rs +++ b/src/client.rs @@ -134,8 +134,7 @@ impl Client { log::info!("rendezvous server: {}", rendezvous_server); let mut socket = - socket_client::connect_tcp(&*rendezvous_server, any_addr, RENDEZVOUS_TIMEOUT) - .await?; + socket_client::connect_tcp(&*rendezvous_server, any_addr, RENDEZVOUS_TIMEOUT).await?; let my_addr = socket.local_addr(); let mut pk = Vec::new(); let mut relay_server = "".to_owned(); @@ -682,6 +681,7 @@ pub struct LoginConfigHandler { pub port_forward: (String, i32), pub support_press: bool, pub support_refresh: bool, + pub internation_keyboard: bool, } impl Deref for LoginConfigHandler { @@ -938,6 +938,7 @@ impl LoginConfigHandler { if !pi.version.is_empty() { self.support_press = true; self.support_refresh = true; + self.internation_keyboard = crate::get_version_number(&pi.version) > 1001008; } let serde = PeerInfoSerde { username, diff --git a/src/server/input_service.rs b/src/server/input_service.rs index ba34772a5..ef06f2348 100644 --- a/src/server/input_service.rs +++ b/src/server/input_service.rs @@ -40,7 +40,8 @@ struct Input { time: i64, } -const KEY_CHAR_START: i32 = 9999; +const KEY_CHAR_START: u64 = 0xFFFF; +const KEY_SYM_START: u64 = 0xFFFFFFFF; #[derive(Clone, Default)] pub struct MouseCursorSub { @@ -163,7 +164,7 @@ fn run_cursor(sp: MouseCursorService, state: &mut StateCursor) -> ResultType<()> lazy_static::lazy_static! { static ref ENIGO: Arc> = Arc::new(Mutex::new(Enigo::new())); - static ref KEYS_DOWN: Arc>> = Default::default(); + static ref KEYS_DOWN: Arc>> = Default::default(); static ref LATEST_INPUT: Arc> = Default::default(); } static EXITING: AtomicBool = AtomicBool::new(false); @@ -256,13 +257,15 @@ fn fix_key_down_timeout(force: bool) { if force || value.elapsed().as_millis() >= 3_000 { KEYS_DOWN.lock().unwrap().remove(&key); let key = if key < KEY_CHAR_START { - if let Some(key) = KEY_MAP.get(&key) { + if let Some(key) = KEY_MAP.get(&(key as _)) { Some(*key) } else { None } - } else { + } else if key < KEY_SYM_START { Some(Key::Layout(((key - KEY_CHAR_START) as u8) as _)) + } else { + Some(Key::KeySym((key - KEY_SYM_START) as u32)) }; if let Some(key) = key { let func = move || { @@ -352,7 +355,10 @@ fn handle_mouse_(evt: &MouseEvent, conn: i32) { modifier_sleep(); to_release.push(key); } else { - KEYS_DOWN.lock().unwrap().insert(ck.value(), Instant::now()); + KEYS_DOWN + .lock() + .unwrap() + .insert(ck.value() as _, Instant::now()); } } } @@ -572,7 +578,10 @@ fn handle_key_(evt: &KeyEvent) { modifier_sleep(); to_release.push(key); } else { - KEYS_DOWN.lock().unwrap().insert(ck.value(), Instant::now()); + KEYS_DOWN + .lock() + .unwrap() + .insert(ck.value() as _, Instant::now()); } } } @@ -606,10 +615,13 @@ fn handle_key_(evt: &KeyEvent) { } if evt.down { allow_err!(en.key_down(key.clone())); - KEYS_DOWN.lock().unwrap().insert(ck.value(), Instant::now()); + KEYS_DOWN + .lock() + .unwrap() + .insert(ck.value() as _, Instant::now()); } else { en.key_up(key.clone()); - KEYS_DOWN.lock().unwrap().remove(&ck.value()); + KEYS_DOWN.lock().unwrap().remove(&(ck.value() as _)); } } 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. @@ -627,13 +639,28 @@ fn handle_key_(evt: &KeyEvent) { KEYS_DOWN .lock() .unwrap() - .insert(chr as i32 + KEY_CHAR_START, Instant::now()); + .insert(chr as u64 + KEY_CHAR_START, Instant::now()); } else { en.key_up(Key::Layout(chr as u8 as _)); KEYS_DOWN .lock() .unwrap() - .remove(&(chr as i32 + KEY_CHAR_START)); + .remove(&(chr as u64 + 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)) => {