From 7775a14c9e9ad7e231b317372f6830e20b714902 Mon Sep 17 00:00:00 2001 From: Asura Date: Tue, 2 Aug 2022 03:47:29 -0700 Subject: [PATCH] Use keycode mapping table --- Cargo.lock | 11 +++++++++++ Cargo.toml | 3 +++ src/server/input_service.rs | 9 +++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 833cbe12a..e341ff459 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4053,6 +4053,7 @@ dependencies = [ "mouce", "num_cpus", "objc", + "once_cell", "parity-tokio-ipc", "rdev", "repng", @@ -4071,6 +4072,7 @@ dependencies = [ "simple_rc", "sys-locale", "sysinfo", + "tfc", "tray-item", "trayicon", "uuid", @@ -4755,6 +4757,15 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +[[package]] +name = "tfc" +version = "0.6.1" +source = "git+https://github.com/asur4s/The-Fat-Controller#35ed0bc8dd8516bdb99e45ebfc94409637a92c6b" +dependencies = [ + "core-graphics 0.22.3", + "unicode-segmentation", +] + [[package]] name = "thiserror" version = "1.0.31" diff --git a/Cargo.toml b/Cargo.toml index 825f0d739..20ec129ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,6 +73,8 @@ sys-locale = "0.2" enigo = { path = "libs/enigo", features = [ "with_serde" ] } clipboard = { path = "libs/clipboard" } rdev = { git = "https://github.com/asur4s/rdev" } +tfc = { git = "https://github.com/asur4s/The-Fat-Controller" } +once_cell = "1.13.0" ctrlc = "3.2" arboard = "2.0" #minreq = { version = "2.4", features = ["punycode", "https-native"] } @@ -103,6 +105,7 @@ async-process = "1.3" mouce = { git="https://github.com/fufesou/mouce.git" } evdev = { git="https://github.com/fufesou/evdev" } + [target.'cfg(target_os = "android")'.dependencies] android_logger = "0.11" jni = "0.19" diff --git a/src/server/input_service.rs b/src/server/input_service.rs index 629ed17e4..e3ac41a59 100644 --- a/src/server/input_service.rs +++ b/src/server/input_service.rs @@ -9,6 +9,7 @@ use std::{ sync::atomic::{AtomicBool, Ordering}, time::Instant, }; +use tfc::{traits::*, Context}; #[derive(Default)] struct StateCursor { @@ -179,6 +180,7 @@ lazy_static::lazy_static! { }; static ref KEYS_DOWN: Arc>> = Default::default(); static ref LATEST_INPUT: Arc> = Default::default(); + static ref KBD_CONTEXT: Mutex = Mutex::new(Context::new().expect("kbd context error")); } static EXITING: AtomicBool = AtomicBool::new(false); @@ -820,9 +822,12 @@ fn legacy_keyboard_mode(evt: &KeyEvent) { } fn translate_keyboard_mode(evt: &KeyEvent) { - dbg!(evt.chr()); let chr = char::from_u32(evt.chr()).unwrap_or_default(); - rdev::simulate_char(chr, evt.down); + if evt.down { + KBD_CONTEXT.lock().unwrap().unicode_char_down(chr).expect("unicode_char_down error"); + } else { + KBD_CONTEXT.lock().unwrap().unicode_char_up(chr).expect("unicode_char_up error"); + } } fn handle_key_(evt: &KeyEvent) {