mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-06-23 00:34:48 +03:00
macos: post NumericPad and SecondaryFn flags for synthesized arrow keys
Hardware-generated arrow key events on macOS carry the NumericPad and SecondaryFn flags in addition to any user-pressed modifiers. CGEventTap- based hotkey matchers (tiling window managers, accessibility tools, etc.) commonly check those flags to disambiguate navigation arrows from generic chords, and reject events that lack them. Before this change, synthesized Option+Arrow chords were silently swallowed by the focused application instead of being captured by the window manager, because the events arrived with only the Alternate flag set. Hardware Option+Arrow chords on the local keyboard worked because the OS itself set the missing flags. Add NumericPad + SecondaryFn to the flags posted with arrow key events (Mac key codes 0x7B-0x7E) so synthesized arrow chords match hardware chords on the wire. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
committed by
Ferdinand Schober
parent
7ef43418c9
commit
82d677f9c8
@@ -157,6 +157,19 @@ extern "C" {
|
||||
fn AXIsProcessTrusted() -> bool;
|
||||
}
|
||||
|
||||
/// Mac virtual key codes for the four arrow keys.
|
||||
const MAC_KEY_LEFT: u16 = 0x7B;
|
||||
const MAC_KEY_RIGHT: u16 = 0x7C;
|
||||
const MAC_KEY_DOWN: u16 = 0x7D;
|
||||
const MAC_KEY_UP: u16 = 0x7E;
|
||||
|
||||
fn is_arrow_key(key: u16) -> bool {
|
||||
matches!(
|
||||
key,
|
||||
MAC_KEY_LEFT | MAC_KEY_RIGHT | MAC_KEY_DOWN | MAC_KEY_UP
|
||||
)
|
||||
}
|
||||
|
||||
fn key_event(event_source: CGEventSource, key: u16, state: u8, modifiers: XMods) {
|
||||
let event = match CGEvent::new_keyboard_event(event_source, key, state != 0) {
|
||||
Ok(e) => e,
|
||||
@@ -165,7 +178,15 @@ fn key_event(event_source: CGEventSource, key: u16, state: u8, modifiers: XMods)
|
||||
return;
|
||||
}
|
||||
};
|
||||
event.set_flags(to_cgevent_flags(modifiers));
|
||||
let mut flags = to_cgevent_flags(modifiers);
|
||||
// Hardware-generated arrow keys on macOS carry NumericPad + SecondaryFn.
|
||||
// CGEventTap-based hotkey matchers (e.g. tiling window managers) check
|
||||
// these flags to recognize navigation keys; without them synthesized
|
||||
// arrow chords fall through to the focused app.
|
||||
if is_arrow_key(key) {
|
||||
flags |= CGEventFlags::CGEventFlagNumericPad | CGEventFlags::CGEventFlagSecondaryFn;
|
||||
}
|
||||
event.set_flags(flags);
|
||||
event.post(CGEventTapLocation::HID);
|
||||
log::trace!("key event: {key} {state}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user