Assigning F keys to menu Items

According to the documentation, I should be able to assign my function keys to menu items using the properties but this doesn’t work, at least I can’t get it to work. I didn’t see any examples on this. The documentation also mentions non-printing characters can be used but I don’t see how unless I have to code it.

What have you tried?

On macOS Sierra, I just set up a menu with F4 as the shortcut and it worked fine. Here’s the Inspector:

Changing the shortcut to F5 in code is done like this:

HelpAbout.KeyboardShortcut = "F5"

Doesn’t macOS (any version) claim most of the “F” keys for itself.
and that attempting to redefine them will cause the “Mac Police” to shun your app because it is not “Mac-Like”? :smiley:

Function keys: You just type in F3 in the Key field in the Inspector. Uncheck MenuModifier. That’s it.

Good point Dave. It would be necessary to interrogate the system preferences for the settings for the function keys (does the user access them with “fn” pressed or not). And then show fn+F4 or just F4 as keyboard shortcut based on this system preference.

No, this is taken care of for you. You just need to set it to be something like “F4” and the system will take care of things (and you’ll match all other apps).

The handling yes. But what I meant with my post is the keyboard shortcut string in the menu item. The fn is not automatically shown in front of the keyboard shortcut should the system preferences be set by the user to “use fn to access the function keys”.

Wasn’t there a page (or more) in the documentation about this ?

http://documentation.xojo.com/index.php/MenuItem *
http://documentation.xojo.com/index.php/MenuItem.KeyboardShortCut

  • Watch the paragraph: Specifying the keyboard shortcut in the Menu Editor …

I’m not convinced an app should do that. The desired accelerator is still F4 (or whatever), even if to get that key on a given keyboard you need to hold down the function key too. If an accelerator was the & character, I would not expect the menu item to say Shift+7.

It is also possible the user has installed an extension to allow setting the “use fn to access the function keys” on an individual key basis. That isn’t an OSX option, but there are third party extensions available to do it.

Bottom line is just listing F4 is still accurate – it is up to the user to know if that requires a concurrent keypress to get it.

IMHO.

Have you considered TouchBar support as well?

MBS Plugin could help with the HotKeyMBS class to catch key combinations.
Or use the NSEventFilterMBS to filter them yourself.
Or for TouchBar, check out the NSTouchBarMBS class.