Menu modifier keys

I want to have a single menuitem and modify its behavior slightly if the user holds a modifier key when pressing the menu shortcut key combo. e.g. Cmd-F and Opt-Cmd-F. (or Shift-Cmd-F would be OK too)

I tried to use Keyboard.OptionKey in the menu handler to distinguish between those cases but the menu handler doesn’t fire at all if the Option key is pressed.

What’s the right approach to implementing menu modifier keys???

To get Option command-F, select the menu option and in the inspector

  • enter F in the Key box
  • Set MenuModifier On (that’s command)
  • Set MacOptionKey On

You will see both option and command symbols before F in the menu as shortcut

Does that fire for both Cmd-F and Opt-Cmd-F?

I tried something similar with the shift modifier and I could only get it to work for one key combo at a time, not both.

It seems that with your suggestion I’d need two separate menu items and thus two commands in the menu??? I’m trying to have just one command in the menu and to slightly alter the behavior based on whether a modifier key was also pressed or not. Ideas??

[quote=139400:@Joe Huber]Does that fire for both Cmd-F and Opt-Cmd-F?

I tried something similar with the shift modifier and I could only get it to work for one key combo at a time, not both.

It seems that with your suggestion I’d need two separate menu items and thus two commands in the menu??? I’m trying to have just one command in the menu and to slightly alter the behavior based on whether a modifier key was also pressed or not. Ideas??[/quote]

The way menus are managed, you can only have one shortcut command per menuitem.

The only way I see to have several key shortcuts would be in addition to use a timer that monitors the keyboard object events, so when the proper key combinations are punched, it calls the same method as the menu handler.

Wouldn’t it be more transparent and self-documenting to have multiple menu items?

I think he is speaking of NSMenuItem’s setAlternate: message.

An example: Safari has a menu item called “Close Tab”. If more than one tab is visible at the same time, depressing the Opt-Key while the File menu is open changes the “Close Tab” entry to “Close Other Tabs”.

[quote=139447:@Eli Ott]I think he is speaking of NSMenuItem’s setAlternate: message.

An example: Safari has a menu item called “Close Tab”. If more than one tab is visible at the same time, depressing the Opt-Key while the File menu is open changes the “Close Tab” entry to “Close Other Tabs”.[/quote]

That makes sense. But then he can have two menu items, one for Cmd-F and another for Ctrl-Cmd-F.

I thought he wanted to get the same result for both, but reading again he does want different results.