win, translate mode, debug
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
347add1874
commit
1294103ba7
@ -200,7 +200,7 @@ pub fn update_grab_get_key_name() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
static mut IS_LAST_0X021D: bool = false;
|
static mut IS_0X021D_DOWN: bool = false;
|
||||||
|
|
||||||
pub fn start_grab_loop() {
|
pub fn start_grab_loop() {
|
||||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||||
@ -210,33 +210,43 @@ pub fn start_grab_loop() {
|
|||||||
if key == Key::CapsLock || key == Key::NumLock {
|
if key == Key::CapsLock || key == Key::NumLock {
|
||||||
return Some(event);
|
return Some(event);
|
||||||
}
|
}
|
||||||
if KEYBOARD_HOOKED.load(Ordering::SeqCst) {
|
|
||||||
let keyboard_mode = client::process_event(&event, None);
|
let mut _keyboard_mode = KeyboardMode::Map;
|
||||||
if keyboard_mode == KeyboardMode::Translate {
|
let scan_code = event.scan_code;
|
||||||
|
let res = if KEYBOARD_HOOKED.load(Ordering::SeqCst) {
|
||||||
|
_keyboard_mode = client::process_event(&event, None);
|
||||||
|
if is_press {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(event)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Some(event)
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
match event.scan_code {
|
match scan_code {
|
||||||
|
0x1D | 0x021D => rdev::set_modifier(Key::ControlLeft, is_press),
|
||||||
|
0xE01D => rdev::set_modifier(Key::ControlRight, is_press),
|
||||||
0x2A => rdev::set_modifier(Key::ShiftLeft, is_press),
|
0x2A => rdev::set_modifier(Key::ShiftLeft, is_press),
|
||||||
0x36 => rdev::set_modifier(Key::ShiftRight, is_press),
|
0x36 => rdev::set_modifier(Key::ShiftRight, is_press),
|
||||||
0x38 => rdev::set_modifier(Key::Alt, is_press),
|
0x38 => rdev::set_modifier(Key::Alt, is_press),
|
||||||
|
// Right Alt
|
||||||
0xE038 => rdev::set_modifier(Key::AltGr, is_press),
|
0xE038 => rdev::set_modifier(Key::AltGr, is_press),
|
||||||
0xE05B => rdev::set_modifier(Key::MetaLeft, is_press),
|
0xE05B => rdev::set_modifier(Key::MetaLeft, is_press),
|
||||||
0xE05C => rdev::set_modifier(Key::MetaRight, is_press),
|
0xE05C => rdev::set_modifier(Key::MetaRight, is_press),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
unsafe {
|
unsafe {
|
||||||
IS_LAST_0X021D = event.scan_code == 0x021D;
|
// AltGr
|
||||||
|
if scan_code == 0x021D {
|
||||||
|
IS_0X021D_DOWN = is_press;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_press {
|
return res;
|
||||||
return None;
|
|
||||||
} else {
|
|
||||||
return Some(event);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Some(event);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let func = move |event: Event| match event.event_type {
|
let func = move |event: Event| match event.event_type {
|
||||||
EventType::KeyPress(key) => try_handle_keyboard(event, key, true),
|
EventType::KeyPress(key) => try_handle_keyboard(event, key, true),
|
||||||
@ -808,7 +818,11 @@ pub fn translate_keyboard_mode(event: &Event, key_event: KeyEvent) -> Vec<KeyEve
|
|||||||
let mut events: Vec<KeyEvent> = Vec::new();
|
let mut events: Vec<KeyEvent> = Vec::new();
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
unsafe {
|
unsafe {
|
||||||
if IS_LAST_0X021D {
|
if event.scan_code == 0x021D {
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
if IS_0X021D_DOWN {
|
||||||
if event.scan_code == 0xE038 {
|
if event.scan_code == 0xE038 {
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
@ -816,7 +830,7 @@ pub fn translate_keyboard_mode(event: &Event, key_event: KeyEvent) -> Vec<KeyEve
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
if !is_hot_key_modifiers_down() {
|
if unsafe {IS_0X021D_DOWN} || !is_hot_key_modifiers_down() {
|
||||||
try_fill_unicode(event, &key_event, &mut events);
|
try_fill_unicode(event, &key_event, &mut events);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,6 @@ struct Input {
|
|||||||
y: i32,
|
y: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const KEY_RDEV_START: u64 = 999;
|
|
||||||
const KEY_CHAR_START: u64 = 9999;
|
const KEY_CHAR_START: u64 = 9999;
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
@ -202,11 +201,17 @@ fn run_cursor(sp: MouseCursorService, state: &mut StateCursor) -> ResultType<()>
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
|
enum KeysDown {
|
||||||
|
RdevKey(RawKey),
|
||||||
|
EnigoKey(u64)
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref ENIGO: Arc<Mutex<Enigo>> = {
|
static ref ENIGO: Arc<Mutex<Enigo>> = {
|
||||||
Arc::new(Mutex::new(Enigo::new()))
|
Arc::new(Mutex::new(Enigo::new()))
|
||||||
};
|
};
|
||||||
static ref KEYS_DOWN: Arc<Mutex<HashMap<u64, Instant>>> = Default::default();
|
static ref KEYS_DOWN: Arc<Mutex<HashMap<KeysDown, Instant>>> = Default::default();
|
||||||
static ref LATEST_PEER_INPUT_CURSOR: Arc<Mutex<Input>> = Default::default();
|
static ref LATEST_PEER_INPUT_CURSOR: Arc<Mutex<Input>> = Default::default();
|
||||||
static ref LATEST_SYS_CURSOR_POS: Arc<Mutex<(Instant, (i32, i32))>> = Arc::new(Mutex::new((Instant::now().sub(MOUSE_MOVE_PROTECTION_TIMEOUT), (0, 0))));
|
static ref LATEST_SYS_CURSOR_POS: Arc<Mutex<(Instant, (i32, i32))>> = Arc::new(Mutex::new((Instant::now().sub(MOUSE_MOVE_PROTECTION_TIMEOUT), (0, 0))));
|
||||||
}
|
}
|
||||||
@ -375,12 +380,7 @@ fn record_key_is_control_key(record_key: u64) -> bool {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn record_key_is_chr(record_key: u64) -> bool {
|
fn record_key_is_chr(record_key: u64) -> bool {
|
||||||
KEY_RDEV_START <= record_key && record_key < KEY_CHAR_START
|
record_key < KEY_CHAR_START
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn record_key_is_rdev_layout(record_key: u64) -> bool {
|
|
||||||
KEY_CHAR_START <= record_key
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -396,16 +396,19 @@ fn record_key_to_key(record_key: u64) -> Option<Key> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn release_record_key(record_key: u64) {
|
fn release_record_key(record_key: KeysDown) {
|
||||||
let func = move || {
|
let func = move || {
|
||||||
if record_key_is_rdev_layout(record_key) {
|
match record_key {
|
||||||
simulate_(&EventType::KeyRelease(RdevKey::Unknown(
|
KeysDown::RdevKey(raw_key) => {
|
||||||
(record_key - KEY_RDEV_START) as _,
|
simulate_(&EventType::KeyRelease(RdevKey::RawKey(raw_key)));
|
||||||
)));
|
}
|
||||||
} else if let Some(key) = record_key_to_key(record_key) {
|
KeysDown::EnigoKey(key) => {
|
||||||
|
if let Some(key) = record_key_to_key(key) {
|
||||||
ENIGO.lock().unwrap().key_up(key);
|
ENIGO.lock().unwrap().key_up(key);
|
||||||
log::debug!("Fixed {:?} timeout", key);
|
log::debug!("Fixed {:?} timeout", key);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
@ -733,7 +736,7 @@ pub fn reset_input_ondisconn() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sim_rdev_rawkey(code: u32, keydown: bool) {
|
fn sim_rdev_rawkey_position(code: u32, keydown: bool) {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let rawkey = RawKey::ScanCode(code);
|
let rawkey = RawKey::ScanCode(code);
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
@ -744,6 +747,23 @@ fn sim_rdev_rawkey(code: u32, keydown: bool) {
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
let rawkey = RawKey::MacVirtualKeycode(code);
|
let rawkey = RawKey::MacVirtualKeycode(code);
|
||||||
|
|
||||||
|
// map mode(1): Send keycode according to the peer platform.
|
||||||
|
record_pressed_key(KeysDown::RdevKey(rawkey), keydown);
|
||||||
|
|
||||||
|
let event_type = if keydown {
|
||||||
|
EventType::KeyPress(RdevKey::RawKey(rawkey))
|
||||||
|
} else {
|
||||||
|
EventType::KeyRelease(RdevKey::RawKey(rawkey))
|
||||||
|
};
|
||||||
|
simulate_(&event_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sim_rdev_rawkey_virtual(code: u32, keydown: bool) {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
let rawkey = RawKey::WinVirtualKeycode(code);
|
||||||
|
|
||||||
|
record_pressed_key(KeysDown::RdevKey(rawkey), keydown);
|
||||||
|
|
||||||
let event_type = if keydown {
|
let event_type = if keydown {
|
||||||
EventType::KeyPress(RdevKey::RawKey(rawkey))
|
EventType::KeyPress(RdevKey::RawKey(rawkey))
|
||||||
} else {
|
} else {
|
||||||
@ -874,9 +894,6 @@ fn sync_numlock_capslock_status(key_event: &KeyEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn map_keyboard_mode(evt: &KeyEvent) {
|
fn map_keyboard_mode(evt: &KeyEvent) {
|
||||||
// map mode(1): Send keycode according to the peer platform.
|
|
||||||
record_pressed_key(evt.chr() as u64 + KEY_CHAR_START, evt.down);
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
crate::platform::windows::try_change_desktop();
|
crate::platform::windows::try_change_desktop();
|
||||||
|
|
||||||
@ -894,7 +911,7 @@ fn map_keyboard_mode(evt: &KeyEvent) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sim_rdev_rawkey(evt.chr(), evt.down);
|
sim_rdev_rawkey_position(evt.chr(), evt.down);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
@ -1011,7 +1028,7 @@ fn release_keys(en: &mut Enigo, to_release: &Vec<Key>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn record_pressed_key(record_key: u64, down: bool) {
|
fn record_pressed_key(record_key: KeysDown, down: bool) {
|
||||||
let mut key_down = KEYS_DOWN.lock().unwrap();
|
let mut key_down = KEYS_DOWN.lock().unwrap();
|
||||||
if down {
|
if down {
|
||||||
key_down.insert(record_key, Instant::now());
|
key_down.insert(record_key, Instant::now());
|
||||||
@ -1050,12 +1067,12 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let record_key = ck.value() as u64;
|
let record_key = ck.value() as u64;
|
||||||
record_pressed_key(record_key, down);
|
record_pressed_key(KeysDown::EnigoKey(record_key), down);
|
||||||
process_control_key(&mut en, &ck, down)
|
process_control_key(&mut en, &ck, down)
|
||||||
}
|
}
|
||||||
Some(key_event::Union::Chr(chr)) => {
|
Some(key_event::Union::Chr(chr)) => {
|
||||||
let record_key = chr as u64 + KEY_CHAR_START;
|
let record_key = chr as u64 + KEY_CHAR_START;
|
||||||
record_pressed_key(record_key, down);
|
record_pressed_key(KeysDown::EnigoKey(record_key), down);
|
||||||
process_chr(&mut en, chr, down)
|
process_chr(&mut en, chr, down)
|
||||||
}
|
}
|
||||||
Some(key_event::Union::Unicode(chr)) => process_unicode(&mut en, chr),
|
Some(key_event::Union::Unicode(chr)) => process_unicode(&mut en, chr),
|
||||||
@ -1069,12 +1086,8 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
|
|||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
fn translate_process_virtual_keycode(vk: u32, down: bool) {
|
fn translate_process_virtual_keycode(vk: u32, down: bool) {
|
||||||
let scancode = rdev::vk_to_scancode(vk);
|
|
||||||
// map mode(1): Send keycode according to the peer platform.
|
|
||||||
record_pressed_key(scancode as u64 + KEY_CHAR_START, down);
|
|
||||||
|
|
||||||
crate::platform::windows::try_change_desktop();
|
crate::platform::windows::try_change_desktop();
|
||||||
sim_rdev_rawkey(scancode, down);
|
sim_rdev_rawkey_virtual(vk, down);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn translate_keyboard_mode(evt: &KeyEvent) {
|
fn translate_keyboard_mode(evt: &KeyEvent) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user