derive is_numpad_key from https://github.com/rustdesk/rustdesk/pull/3785/files
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
2f7245495d
commit
fc98b0355e
@ -46,35 +46,6 @@ lazy_static::lazy_static! {
|
||||
m.insert(Key::MetaRight, false);
|
||||
Mutex::new(m)
|
||||
};
|
||||
static ref NUMPAD_POSITION_CODES: Arc<Vec<KeyCode>> = {
|
||||
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user