working on keysym

This commit is contained in:
open-trade 2022-01-07 18:03:55 +08:00
parent 9df1fcb783
commit 26d161f827
7 changed files with 48 additions and 12 deletions

View File

@ -418,6 +418,8 @@ 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,6 +181,9 @@ 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("");
}
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,6 +426,7 @@ 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,6 +340,7 @@ 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

@ -172,6 +172,7 @@ 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

@ -134,8 +134,7 @@ impl Client {
log::info!("rendezvous server: {}", rendezvous_server); log::info!("rendezvous server: {}", rendezvous_server);
let mut socket = let mut socket =
socket_client::connect_tcp(&*rendezvous_server, any_addr, RENDEZVOUS_TIMEOUT) socket_client::connect_tcp(&*rendezvous_server, any_addr, RENDEZVOUS_TIMEOUT).await?;
.await?;
let my_addr = socket.local_addr(); let my_addr = socket.local_addr();
let mut pk = Vec::new(); let mut pk = Vec::new();
let mut relay_server = "".to_owned(); let mut relay_server = "".to_owned();
@ -682,6 +681,7 @@ pub struct LoginConfigHandler {
pub port_forward: (String, i32), pub port_forward: (String, i32),
pub support_press: bool, pub support_press: bool,
pub support_refresh: bool, pub support_refresh: bool,
pub internation_keyboard: bool,
} }
impl Deref for LoginConfigHandler { impl Deref for LoginConfigHandler {
@ -938,6 +938,7 @@ impl LoginConfigHandler {
if !pi.version.is_empty() { if !pi.version.is_empty() {
self.support_press = true; self.support_press = true;
self.support_refresh = true; self.support_refresh = true;
self.internation_keyboard = crate::get_version_number(&pi.version) > 1001008;
} }
let serde = PeerInfoSerde { let serde = PeerInfoSerde {
username, username,

View File

@ -40,7 +40,8 @@ struct Input {
time: i64, time: i64,
} }
const KEY_CHAR_START: i32 = 9999; const KEY_CHAR_START: u64 = 0xFFFF;
const KEY_SYM_START: u64 = 0xFFFFFFFF;
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct MouseCursorSub { pub struct MouseCursorSub {
@ -163,7 +164,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<i32, Instant>>> = Default::default(); static ref KEYS_DOWN: Arc<Mutex<HashMap<u64, 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);
@ -256,13 +257,15 @@ 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) { if let Some(key) = KEY_MAP.get(&(key as _)) {
Some(*key) Some(*key)
} else { } else {
None None
} }
} else { } else if key < KEY_SYM_START {
Some(Key::Layout(((key - KEY_CHAR_START) as u8) as _)) 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 { if let Some(key) = key {
let func = move || { let func = move || {
@ -352,7 +355,10 @@ fn handle_mouse_(evt: &MouseEvent, conn: i32) {
modifier_sleep(); modifier_sleep();
to_release.push(key); to_release.push(key);
} else { } 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(); modifier_sleep();
to_release.push(key); to_release.push(key);
} else { } 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 { if evt.down {
allow_err!(en.key_down(key.clone())); 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 { } else {
en.key_up(key.clone()); 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() { } 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.
@ -627,13 +639,28 @@ fn handle_key_(evt: &KeyEvent) {
KEYS_DOWN KEYS_DOWN
.lock() .lock()
.unwrap() .unwrap()
.insert(chr as i32 + KEY_CHAR_START, Instant::now()); .insert(chr as u64 + 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 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)) => { Some(key_event::Union::unicode(chr)) => {