Reputation: 2208
I'm writing a macOS app that can simulate keystrokes based off of a text description of a keystroke, such as "Command+R". One of the goals of this is to be able to trigger system-wide keyboard shortcuts.
In that case, it's not enough to simply type a key with a particular keycode and some combination of the command, option, control, and shift modifiers. Keystrokes involving the numpad, navigation or function keys also require posting an event with the "numpad" or "secondary function" modifier flags, i.e. kCGEventFlagMaskNumericPad
and kCGEventFlagMaskSecondaryFn
respectively.
In the case of kCGEventFlagMaskNumericPad, it's obvious when to use it: when the keycode is for a key on the numeric pad.
kCGEventFlagMaskSecondaryFn
however is less clear. It's defined as being the modifier when the "Fn" key is held down, but in practice the key up / key down events generated by certain keys on the keyboard will always have that flag set, regardless of what the user is doing with their "Fn" key. And if you don't set the kCGEventFlagMaskSecondaryFn
flag when generating a keyboard event involving one of these keys, it won't trigger a system-wide keyboard shortcut.
So far I've identified the following keys that normally include and require the kCGEventFlagMaskSecondaryFn
flag: Ins / Help, Forward Delete, Home, End, Page Up, Page Down, the arrow keys, and all function keys.
The first question is, am I correct that these keys should always have the kCGEventFlagMaskSecondaryFn
flag set, or are there cases where they shouldn't?
The second question is, are there any others I've missed?
I've only tested with a US Keyboard layout and I'm wondering if there are other keyboard layouts that include keys I'm not aware of that require kCGEventFlagMaskSecondaryFn
?
Upvotes: -1
Views: 16