Refactor translate mode

This commit is contained in:
Asura 2022-08-11 23:59:18 -07:00
parent 577cce549f
commit b916ef3659
3 changed files with 7 additions and 16 deletions

4
Cargo.lock generated
View File

@ -3740,7 +3740,7 @@ dependencies = [
[[package]]
name = "rdev"
version = "0.5.0-2"
source = "git+https://github.com/asur4s/rdev#3b440f7ff9d622b08eb83146ea3e5e529769a6c2"
source = "git+https://github.com/asur4s/rdev#895c8fb1a6106714793e8877d35d2b7a1c57ce9c"
dependencies = [
"cocoa",
"core-foundation 0.9.3",
@ -4712,7 +4712,7 @@ checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
[[package]]
name = "tfc"
version = "0.6.1"
source = "git+https://github.com/asur4s/The-Fat-Controller#34ee2472e6a88dd8f0e28113d50130d93cf8a572"
source = "git+https://github.com/asur4s/The-Fat-Controller#25bfa7ef1cb0bd0b522cc4155dea6b99673bcfd4"
dependencies = [
"core-graphics 0.22.3",
"unicode-segmentation",

View File

@ -822,16 +822,10 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
}
fn translate_keyboard_mode(evt: &KeyEvent) {
// Caps affects the keycode map of the peer system(Linux).
let mut en = ENIGO.lock().unwrap();
if en.get_key_state(Key::CapsLock){
rdev_key_click(RdevKey::CapsLock);
}
let chr = char::from_u32(evt.chr()).unwrap_or_default();
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");
// down(true)->press && press(false)-> release
if evt.down && !evt.press {
KBD_CONTEXT.lock().unwrap().unicode_char(chr).expect("unicode_char_down error");
}
}

View File

@ -1108,11 +1108,8 @@ impl Handler {
let mut key_event = KeyEvent::new();
key_event.set_chr(chr as _);
key_event.down = true;
self.send_key_event(key_event, KeyboardMode::Translate);
let mut key_event = KeyEvent::new();
key_event.set_chr(chr as _);
key_event.down = false;
key_event.press = false;
self.send_key_event(key_event, KeyboardMode::Translate);
}
} else {