Skip to content

fix(macos): set the Fn flag on emulated F-keys - #524

Open
ShimmerGlass wants to merge 1 commit into
feschber:mainfrom
ShimmerGlass:fix/macos-fkey-fn-flag
Open

ShimmerGlass wants to merge 1 commit into
feschber:mainfrom
ShimmerGlass:fix/macos-fkey-fn-flag

Conversation

@ShimmerGlass

Copy link
Copy Markdown

Summary

Emulated F1–F20 key events on macOS are now posted with the Fn (SecondaryFn) flag, so shortcuts bound to F-keys in System Settings fire.

Changes

  • input-emulation/src/macos.rs: add MAC_FUNCTION_KEYS and is_function_key, and set CGEventFlagSecondaryFn in key_event for F1–F20, mirroring the existing arrow-key handling.
  • Unit test function_keys_are_recognized.

Scope notes

  • Problem: Print Screen from a Linux sender reaches macOS as F13 (macos: map Print Screen / Scroll Lock / Pause to F13/F14/F15 #445), but binding F13 to a screenshot in System Settings > Keyboard Shortcuts does nothing.
  • macOS records F-key shortcuts with the Fn modifier (defaults read com.apple.symbolichotkeys shows e.g. (65535, 105, 8388608) for F13), and real Apple keyboards set SecondaryFn on F-keys. Emulated F1–F20 lacked the flag, so symbolic hotkeys never matched. Raw-keycode tools like skhd don't check the flag, which is why macos: map Print Screen / Scroll Lock / Pause to F13/F14/F15 #445's testing didn't catch it.
  • Only the macOS emulation backend is touched.

Verification

  • Unit test function_keys_are_recognized added.
  • cargo test -p input-emulation, cargo fmt, and cargo clippy --workspace --all-targets --all-features pass. Only pre-existing must_use warnings in input-capture/src/lib.rs and input-emulation/src/lib.rs remain.
  • Root cause verified against the reporter's symbolichotkeys binding.
  • End-to-end on a real Mac not yet verified.

No issue number is associated with this change.

🤖 Generated with Claude Code

Hardware F-keys on macOS carry kCGEventFlagMaskSecondaryFn, and System
Settings stores F-key shortcuts with that modifier (NSEventModifierFlagFunction,
8388608). Emulated F-keys were posted without it, so shortcuts bound to them
never fired, e.g. a screenshot bound to F13, which is what Print Screen from
a Linux/Windows sender maps to since feschber#445.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants