Shortcuts don't fire application commands


#1

I have created a native menubar. The native menubar fires application commands that have been registered using the ApplicationCommandManager and ApplicationCommandTarget just fine but only if I use the mouse to select a menu entry. The keyboard shortcuts registered for the commands don’t fire the associated commands even though they are shown as the keyboard shortcut in the menu entry.

When I press the keyboard shortcut I see the correct menu item highlighted, only the actual command is not fired.

Menu entries are created like this:

...
menu.addCommandItem(commandManager, sc::CommandIDs::settings);
...

and the native menubar is then set using:

...
appleMenu = createAppleMenu();
juce::MenuBarModel::setMacMainMenu(menuModel, &appleMenu, "Open Recent");
...

Commands are registered like this in getCommandInfo():

switch (commandID)
{
...
case sc::CommandIDs::settings:
  result.setInfo(sc::Resources::Translate("Settings"), sc::Resources::Translate("Settings Desc"), sc::CommandCategories::general, 0);
  result.defaultKeypresses.add(juce::KeyPress(',', juce::ModifierKeys::commandModifier, 0));
  break;
...

As said the menu entries work, but only with the mouse. Very strange. Any ideas what I may be missing?


#2

I use key shortcuts like that every day in the introjucer, and those work ok… (?)


#3

Sure, actually the Introjucer was my template how to implement it. Can you point me to where in JUCE I should start debugging, where I can start examining how a shortcut keypress is routed to menus/commands?


#4

Maybe start from ComponentPeer::handleKeyPress and work your way down from there…


#5

How embarrassing. Lets see, how can I phrase this… I forgot a “key” ingredient:

addKeyListener(commandManager->getKeyMappings());

:oops:


#6

Not so embarrassing - the command-manager stuff is quite a complex beastie to work with.