diff --git a/Cargo.lock b/Cargo.lock index a33e523c2..65ae17357 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4674,7 +4674,7 @@ dependencies = [ [[package]] name = "rdev" version = "0.5.0-2" -source = "git+https://github.com/fufesou/rdev#cd0d6ad907f8fda5cf77487bc962ef4246221d0c" +source = "git+https://github.com/fufesou/rdev#0dad4a59f911fe14934fefc8eed18d58cb057a81" dependencies = [ "cocoa", "core-foundation 0.9.3", diff --git a/src/keyboard.rs b/src/keyboard.rs index 8fec0ec3f..f2a6c6833 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -46,35 +46,6 @@ lazy_static::lazy_static! { m.insert(Key::MetaRight, false); Mutex::new(m) }; - static ref NUMPAD_POSITION_CODES: Arc> = { - let numpad_keys = [ - Key::KpMinus, - Key::KpPlus, - Key::KpMultiply, - Key::KpDivide, - Key::KpDecimal, - Key::KpReturn, - Key::KpEqual, - Key::KpComma, - Key::Kp0, - Key::Kp1, - Key::Kp2, - Key::Kp3, - Key::Kp4, - Key::Kp5, - Key::Kp6, - Key::Kp7, - Key::Kp8, - Key::Kp9, - ]; - #[cfg(target_os = "windows")] - let codes = numpad_keys.iter().filter_map(|k| rdev::win_scancode_from_key(*k)).collect(); - #[cfg(target_os = "linux")] - let codes = numpad_keys.iter().filter_map(|k| rdev::linux_keycode_from_key(*k)).collect(); - #[cfg(target_os = "macos")] - let codes = numpad_keys.iter().filter_map(|k| rdev::macos_keycode_from_key(*k)).collect(); - Arc::new(codes) - }; } pub mod client { @@ -390,6 +361,16 @@ pub fn get_keyboard_mode_enum() -> KeyboardMode { } } +#[inline] +fn is_numpad_key(event: &Event) -> bool { + matches!(event.event_type, EventType::KeyPress(key) | EventType::KeyRelease(key) if match 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 + }) +} + #[cfg(not(any(target_os = "android", target_os = "ios")))] fn parse_add_lock_modes_modifiers(key_event: &mut KeyEvent, lock_modes: i32, is_numpad_key: bool) { const CAPS_LOCK: i32 = 1; @@ -496,7 +477,7 @@ pub fn event_to_key_events( }; if keyboard_mode != KeyboardMode::Translate { - let is_numpad_key = NUMPAD_POSITION_CODES.contains(&(event.position_code as _)); + let is_numpad_key = is_numpad_key(&event.event_type); for key_event in &mut key_events { #[cfg(not(any(target_os = "android", target_os = "ios")))] if let Some(lock_modes) = lock_modes {