Reputation: 456
I am working on a third-party plugin in a host application (Finale). My plugin can tell Finale to create any number of menu options in its designated menu. My plugin can then fish them out and rearrange that menu after Finale has finished building all its menus.
The user interface of a third-party plugin in Finale is somewhat limited, and a common pattern is to open a modal dialog, set some options, and then hit okay. Continually interrupting workflow with dialog boxes is disruptive, however, so that pattern has often been revised to remember the dialog box settings and use them automatically unless the menu option is selected with a modifier key. (E.g., Option
in macOS or Alt
or Shift
in Windows.)
This works great when a human is selecting the menu option, but given the absurd proliferation of menu options in Finale itself and then potentially tenfold with plugins, most users use a keyboard macro program such as Keyboard Maestro or yKey to select menu options in Finale. The challenge I'm facing is how to see when a keyboard macro program (specifically in macOS) is selecting a menu option with a modifier key.
First I looked at using [NSMenuItem alternate]
. But there are two drawbacks to that:
Currently, to get the modifier keys my plugin is using:
[[[[NSApp currentEvent] modifierFlags];
(The current event when a human selects the menu options is a mouse-up event.)
I have also tried
[NSEvent modifierFlags];
and (for the Option
key)
CGEventSourceKeyState ( kCGEventSourceStateCombinedSessionState, kVK_Option );
All of these work equally well with a human selecting the menu option. None of them work with Keyboard Maestro or yKey, that I have been able to figure out. I have yKey and a colleague has Keyboard Maestro, and the obvious pattern to try for the macro (in pseudocode) is
press option key
select menu option
perhaps wait a few ms
release option key
That does not work. My colleague has also tried programming Keyboard Maestro to actually select the menu option with the mouse, but he says that does not work either. It seems that the above techniques for reading the modifiers read the actual keyboard state and don't care about what a keyboard macro is doing.
My question is this: is there another way to check modifier keys that I haven't discovered? Does anyone have suggestions for how to do this? Maybe some other trigger entirely that a keyboard macro could use when selecting a menu item, leaving modifier keys for the humans.
Upvotes: 0
Views: 74