tmp commit
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
5a0f03eb0d
commit
f72593c281
@ -359,9 +359,6 @@ impl Enigo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn key_to_keycode(&self, key: Key) -> u16 {
|
fn key_to_keycode(&self, key: Key) -> u16 {
|
||||||
unsafe {
|
|
||||||
LAYOUT = std::ptr::null_mut();
|
|
||||||
}
|
|
||||||
// do not use the codes from crate winapi they're
|
// do not use the codes from crate winapi they're
|
||||||
// wrongly typed with i32 instead of i16 use the
|
// wrongly typed with i32 instead of i16 use the
|
||||||
// ones provided by win/keycodes.rs that are prefixed
|
// ones provided by win/keycodes.rs that are prefixed
|
||||||
@ -456,6 +453,9 @@ impl Enigo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_layoutdependent_keycode(&self, chr: char) -> u16 {
|
fn get_layoutdependent_keycode(&self, chr: char) -> u16 {
|
||||||
|
unsafe {
|
||||||
|
LAYOUT = std::ptr::null_mut();
|
||||||
|
}
|
||||||
// NOTE VkKeyScanW uses the current keyboard LAYOUT
|
// NOTE VkKeyScanW uses the current keyboard LAYOUT
|
||||||
// to specify a LAYOUT use VkKeyScanExW and GetKeyboardLayout
|
// to specify a LAYOUT use VkKeyScanExW and GetKeyboardLayout
|
||||||
// or load one with LoadKeyboardLayoutW
|
// or load one with LoadKeyboardLayoutW
|
||||||
|
@ -364,26 +364,73 @@ pub fn is_modifier(key: &rdev::Key) -> bool {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
pub fn is_numpad_rdev_key(key: &rdev::Key) -> bool {
|
||||||
|
matches!(
|
||||||
|
key,
|
||||||
|
Key::Kp0
|
||||||
|
| Key::Kp1
|
||||||
|
| Key::Kp2
|
||||||
|
| Key::Kp3
|
||||||
|
| Key::Kp4
|
||||||
|
| Key::Kp5
|
||||||
|
| Key::Kp6
|
||||||
|
| Key::Kp7
|
||||||
|
| Key::Kp8
|
||||||
|
| Key::Kp9
|
||||||
|
| Key::KpMinus
|
||||||
|
| Key::KpMultiply
|
||||||
|
| Key::KpDivide
|
||||||
|
| Key::KpPlus
|
||||||
|
| Key::KpDecimal
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
pub fn is_letter_rdev_key(key: &rdev::Key) -> bool {
|
||||||
|
matches!(
|
||||||
|
key,
|
||||||
|
Key::KeyA
|
||||||
|
| Key::KeyB
|
||||||
|
| Key::KeyC
|
||||||
|
| Key::KeyD
|
||||||
|
| Key::KeyE
|
||||||
|
| Key::KeyF
|
||||||
|
| Key::KeyG
|
||||||
|
| Key::KeyH
|
||||||
|
| Key::KeyI
|
||||||
|
| Key::KeyJ
|
||||||
|
| Key::KeyK
|
||||||
|
| Key::KeyL
|
||||||
|
| Key::KeyM
|
||||||
|
| Key::KeyN
|
||||||
|
| Key::KeyO
|
||||||
|
| Key::KeyP
|
||||||
|
| Key::KeyQ
|
||||||
|
| Key::KeyR
|
||||||
|
| Key::KeyS
|
||||||
|
| Key::KeyT
|
||||||
|
| Key::KeyU
|
||||||
|
| Key::KeyV
|
||||||
|
| Key::KeyW
|
||||||
|
| Key::KeyX
|
||||||
|
| Key::KeyY
|
||||||
|
| Key::KeyZ
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
fn is_numpad_key(event: &Event) -> bool {
|
fn is_numpad_key(event: &Event) -> bool {
|
||||||
matches!(event.event_type, EventType::KeyPress(key) | EventType::KeyRelease(key) if match key {
|
matches!(event.event_type, EventType::KeyPress(key) | EventType::KeyRelease(key) if is_numpad_rdev_key(&key))
|
||||||
Key::Kp0 | Key::Kp1 | Key::Kp2 | Key::Kp3 | Key::Kp4 | Key::Kp5 | Key::Kp6 | Key::Kp7 | Key::Kp8 |
|
|
||||||
Key::Kp9 | Key::KpMinus | Key::KpMultiply | Key::KpDivide | Key::KpPlus | Key::KpDecimal => true,
|
|
||||||
_ => false
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
fn is_letter_key(event: &Event) -> bool {
|
fn is_letter_key(event: &Event) -> bool {
|
||||||
matches!(event.event_type, EventType::KeyPress(key) | EventType::KeyRelease(key) if match key {
|
matches!(event.event_type, EventType::KeyPress(key) | EventType::KeyRelease(key) if is_letter_rdev_key(&key))
|
||||||
Key::KeyA | Key::KeyB | Key::KeyC | Key::KeyD | Key::KeyE | Key::KeyF | Key::KeyG | Key::KeyH |
|
|
||||||
Key::KeyI | Key::KeyJ | Key::KeyK | Key::KeyL | Key::KeyM | Key::KeyN | Key::KeyO | Key::KeyP |
|
|
||||||
Key::KeyQ | Key::KeyR | Key::KeyS | Key::KeyT | Key::KeyU | Key::KeyV | Key::KeyW | Key::KeyX |
|
|
||||||
Key::KeyY | Key::KeyZ => true,
|
|
||||||
_ => false
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
pub mod platform;
|
pub mod platform;
|
||||||
mod keyboard;
|
mod keyboard;
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
pub use keyboard::keycode_to_rdev_key;
|
pub use keyboard::{keycode_to_rdev_key, is_numpad_rdev_key, is_letter_rdev_key};
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
pub use platform::{get_cursor, get_cursor_data, get_cursor_pos, start_os_service};
|
pub use platform::{get_cursor, get_cursor_data, get_cursor_pos, start_os_service};
|
||||||
#[cfg(not(any(target_os = "ios")))]
|
#[cfg(not(any(target_os = "ios")))]
|
||||||
|
@ -8,13 +8,14 @@ use hbb_common::{config::COMPRESS_LEVEL, get_time, protobuf::EnumOrUnknown};
|
|||||||
use rdev::{self, EventType, Key as RdevKey, KeyCode, RawKey};
|
use rdev::{self, EventType, Key as RdevKey, KeyCode, RawKey};
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use rdev::{CGEventSourceStateID, CGEventTapLocation, VirtualInput};
|
use rdev::{CGEventSourceStateID, CGEventTapLocation, VirtualInput};
|
||||||
use std::time::Duration;
|
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||||
|
use std::collections::HashSet;
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryFrom,
|
convert::TryFrom,
|
||||||
ops::Sub,
|
ops::Sub,
|
||||||
sync::atomic::{AtomicBool, Ordering},
|
sync::atomic::{AtomicBool, Ordering},
|
||||||
thread,
|
thread,
|
||||||
time::{self, Instant},
|
time::{self, Duration, Instant},
|
||||||
};
|
};
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
use winapi::um::winuser::{
|
use winapi::um::winuser::{
|
||||||
@ -153,7 +154,15 @@ impl LockModesHandler {
|
|||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
let disable_numlock = false;
|
let disable_numlock = false;
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let disable_numlock = is_numlock_disabled(key_event);
|
let disable_numlock = if key_event.mode == KeyboardMode::Legacy.into() {
|
||||||
|
// disable numlock if press home etc when numlock is on,
|
||||||
|
// because we will get numpad value (7,8,9 etc) if not
|
||||||
|
has_numpad_key(key_event)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
let disable_numlock = false;
|
||||||
|
println!("REMOVE ME ======================= event_num_enabled {}, local_num_enabled {}", event_num_enabled, local_num_enabled);
|
||||||
let num_lock_changed = event_num_enabled != local_num_enabled && !disable_numlock;
|
let num_lock_changed = event_num_enabled != local_num_enabled && !disable_numlock;
|
||||||
if num_lock_changed {
|
if num_lock_changed {
|
||||||
en.key_click(enigo::Key::NumLock);
|
en.key_click(enigo::Key::NumLock);
|
||||||
@ -1020,35 +1029,6 @@ fn has_numpad_key(key_event: &KeyEvent) -> bool {
|
|||||||
!= 0
|
!= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
fn is_rdev_numpad_key(key_event: &KeyEvent) -> bool {
|
|
||||||
let code = key_event.chr();
|
|
||||||
let key = rdev::get_win_key(code, 0);
|
|
||||||
match key {
|
|
||||||
RdevKey::Home
|
|
||||||
| RdevKey::UpArrow
|
|
||||||
| RdevKey::PageUp
|
|
||||||
| RdevKey::LeftArrow
|
|
||||||
| RdevKey::RightArrow
|
|
||||||
| RdevKey::End
|
|
||||||
| RdevKey::DownArrow
|
|
||||||
| RdevKey::PageDown
|
|
||||||
| RdevKey::Insert
|
|
||||||
| RdevKey::Delete => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
fn is_numlock_disabled(key_event: &KeyEvent) -> bool {
|
|
||||||
// disable numlock if press home etc when numlock is on,
|
|
||||||
// because we will get numpad value (7,8,9 etc) if not
|
|
||||||
match key_event.mode.unwrap() {
|
|
||||||
KeyboardMode::Map => is_rdev_numpad_key(key_event),
|
|
||||||
_ => has_numpad_key(key_event),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn map_keyboard_mode(evt: &KeyEvent) {
|
fn map_keyboard_mode(evt: &KeyEvent) {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
crate::platform::windows::try_change_desktop();
|
crate::platform::windows::try_change_desktop();
|
||||||
@ -1383,15 +1363,29 @@ fn skip_led_sync_control_key(_evt: &KeyEvent) -> bool {
|
|||||||
// https://github.com/rustdesk/rustdesk/issues/3928#issuecomment-1500773473
|
// https://github.com/rustdesk/rustdesk/issues/3928#issuecomment-1500773473
|
||||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||||
fn skip_led_sync_control_key(key: &ControlKey) -> bool {
|
fn skip_led_sync_control_key(key: &ControlKey) -> bool {
|
||||||
[
|
matches!(
|
||||||
ControlKey::Control,
|
key,
|
||||||
ControlKey::Meta,
|
ControlKey::Control
|
||||||
ControlKey::Shift,
|
| ControlKey::RControl
|
||||||
ControlKey::Alt,
|
| ControlKey::Meta
|
||||||
ControlKey::Tab,
|
| ControlKey::Shift
|
||||||
ControlKey::Return,
|
| ControlKey::RShift
|
||||||
]
|
| ControlKey::Alt
|
||||||
.contains(key)
|
| ControlKey::RAlt
|
||||||
|
| ControlKey::Tab
|
||||||
|
| ControlKey::Return
|
||||||
|
| ControlKey::Numpad0
|
||||||
|
| ControlKey::Numpad1
|
||||||
|
| ControlKey::Numpad2
|
||||||
|
| ControlKey::Numpad3
|
||||||
|
| ControlKey::Numpad4
|
||||||
|
| ControlKey::Numpad5
|
||||||
|
| ControlKey::Numpad6
|
||||||
|
| ControlKey::Numpad7
|
||||||
|
| ControlKey::Numpad8
|
||||||
|
| ControlKey::Numpad9
|
||||||
|
| ControlKey::NumpadEnter
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
|
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
|
||||||
@ -1401,19 +1395,20 @@ fn skip_led_sync_rdev_key(_evt: &KeyEvent) -> bool {
|
|||||||
|
|
||||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||||
fn skip_led_sync_rdev_key(key: &RdevKey) -> bool {
|
fn skip_led_sync_rdev_key(key: &RdevKey) -> bool {
|
||||||
[
|
crate::is_numpad_rdev_key(key)
|
||||||
RdevKey::ControlLeft,
|
|| matches!(
|
||||||
RdevKey::ControlRight,
|
key,
|
||||||
RdevKey::MetaLeft,
|
RdevKey::ControlLeft
|
||||||
RdevKey::MetaRight,
|
| RdevKey::ControlRight
|
||||||
RdevKey::ShiftRight,
|
| RdevKey::MetaLeft
|
||||||
RdevKey::ShiftRight,
|
| RdevKey::MetaRight
|
||||||
RdevKey::Alt,
|
| RdevKey::ShiftLeft
|
||||||
RdevKey::AltGr,
|
| RdevKey::ShiftRight
|
||||||
RdevKey::Tab,
|
| RdevKey::Alt
|
||||||
RdevKey::Return,
|
| RdevKey::AltGr
|
||||||
]
|
| RdevKey::Tab
|
||||||
.contains(key)
|
| RdevKey::Return
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_key_(evt: &KeyEvent) {
|
pub fn handle_key_(evt: &KeyEvent) {
|
||||||
@ -1421,6 +1416,8 @@ pub fn handle_key_(evt: &KeyEvent) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("REMOVE ME ============================== {:?}", &evt);
|
||||||
|
|
||||||
let mut _lock_mode_handler = None;
|
let mut _lock_mode_handler = None;
|
||||||
match (&evt.union, evt.mode.enum_value_or(KeyboardMode::Legacy)) {
|
match (&evt.union, evt.mode.enum_value_or(KeyboardMode::Legacy)) {
|
||||||
(Some(key_event::Union::Unicode(..)) | Some(key_event::Union::Seq(..)), _) => {
|
(Some(key_event::Union::Unicode(..)) | Some(key_event::Union::Seq(..)), _) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user