fix, legacy mode, numlock
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
241cb1d24e
commit
2ce1df1ad4
@ -162,13 +162,15 @@ impl LockModesHandler {
|
|||||||
|
|
||||||
let mut num_lock_changed = false;
|
let mut num_lock_changed = false;
|
||||||
if is_numpad_key {
|
if is_numpad_key {
|
||||||
let event_num_enabled = Self::is_modifier_enabled(key_event, ControlKey::NumLock);
|
|
||||||
let local_num_enabled = en.get_key_state(enigo::Key::NumLock);
|
let local_num_enabled = en.get_key_state(enigo::Key::NumLock);
|
||||||
#[cfg(not(target_os = "windows"))]
|
let event_num_enabled = Self::is_modifier_enabled(key_event, ControlKey::NumLock);
|
||||||
let disable_numlock = false;
|
num_lock_changed = event_num_enabled != local_num_enabled;
|
||||||
|
} else if is_legacy_mode(key_event) {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let disable_numlock = is_numlock_disabled(key_event);
|
{
|
||||||
num_lock_changed = event_num_enabled != local_num_enabled && !disable_numlock;
|
num_lock_changed =
|
||||||
|
should_disable_numlock(key_event) && en.get_key_state(enigo::Key::NumLock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if num_lock_changed {
|
if num_lock_changed {
|
||||||
en.key_click(enigo::Key::NumLock);
|
en.key_click(enigo::Key::NumLock);
|
||||||
@ -221,14 +223,16 @@ impl Drop for LockModesHandler {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
fn is_numlock_disabled(key_event: &KeyEvent) -> bool {
|
fn should_disable_numlock(evt: &KeyEvent) -> bool {
|
||||||
// disable numlock if press home etc when numlock is on,
|
// disable numlock if press home etc when numlock is on,
|
||||||
// because we will get numpad value (7,8,9 etc) if not
|
// because we will get numpad value (7,8,9 etc) if not
|
||||||
if is_legacy_mode(&key_event) {
|
match (&evt.union, evt.mode.enum_value_or(KeyboardMode::Legacy)) {
|
||||||
has_numpad_key(key_event)
|
(Some(key_event::Union::ControlKey(ck)), KeyboardMode::Legacy) => {
|
||||||
} else {
|
return NUMPAD_KEY_MAP.contains_key(&ck.value());
|
||||||
false
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const NAME_CURSOR: &'static str = "mouse_cursor";
|
pub const NAME_CURSOR: &'static str = "mouse_cursor";
|
||||||
@ -1037,16 +1041,6 @@ fn char_value_to_key(value: u32) -> Key {
|
|||||||
Key::Layout(std::char::from_u32(value).unwrap_or('\0'))
|
Key::Layout(std::char::from_u32(value).unwrap_or('\0'))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
fn has_numpad_key(key_event: &KeyEvent) -> bool {
|
|
||||||
key_event
|
|
||||||
.modifiers
|
|
||||||
.iter()
|
|
||||||
.filter(|&&ck| NUMPAD_KEY_MAP.get(&ck.value()).is_some())
|
|
||||||
.count()
|
|
||||||
!= 0
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
||||||
@ -1461,12 +1455,7 @@ pub fn handle_key_(evt: &KeyEvent) {
|
|||||||
let is_numpad_key = false;
|
let is_numpad_key = false;
|
||||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||||
let is_numpad_key = is_numpad_control_key(&key);
|
let is_numpad_key = is_numpad_control_key(&key);
|
||||||
// Legacy mode need to disable numlock if home/end/arraws/page down/page up
|
_lock_mode_handler = Some(LockModesHandler::new_handler(&evt, is_numpad_key));
|
||||||
// are pressed.
|
|
||||||
_lock_mode_handler = Some(LockModesHandler::new_handler(
|
|
||||||
&evt,
|
|
||||||
is_numpad_key || is_legacy_mode(evt),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(key_event::Union::Chr(code)) => {
|
Some(key_event::Union::Chr(code)) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user