# Shortcuts don't fire application commands

**URL:** <https://forum.juce.com/t/shortcuts-dont-fire-application-commands/10411>\
**Category:** MacOSX and iOS\
**Created:** [May 7, 2013, 9:23am UTC](https://forum.juce.com/t/shortcuts-dont-fire-application-commands/10411 "2013-05-07T09:23:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![P4tr3ck](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@P4tr3ck](https://forum.juce.com/u/P4tr3ck)\
**Post date:** [May 7, 2013, 9:23am UTC](https://forum.juce.com/t/shortcuts-dont-fire-application-commands/10411/1 "2013-05-07T09:23:06Z")

</div>

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:

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

and the native menubar is then set using:

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

Commands are registered like this in getCommandInfo():

```auto
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?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 7, 2013, 9:43am UTC](https://forum.juce.com/t/shortcuts-dont-fire-application-commands/10411/2 "2013-05-07T09:43:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![P4tr3ck](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@P4tr3ck](https://forum.juce.com/u/P4tr3ck)\
**Post date:** [May 7, 2013, 9:54am UTC](https://forum.juce.com/t/shortcuts-dont-fire-application-commands/10411/3 "2013-05-07T09:54:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 7, 2013, 9:55am UTC](https://forum.juce.com/t/shortcuts-dont-fire-application-commands/10411/4 "2013-05-07T09:55:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![P4tr3ck](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@P4tr3ck](https://forum.juce.com/u/P4tr3ck)\
**Post date:** [May 7, 2013, 10:46am UTC](https://forum.juce.com/t/shortcuts-dont-fire-application-commands/10411/5 "2013-05-07T10:46:27Z")

</div>

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

addKeyListener(commandManager-\>getKeyMappings());

:oops:

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 7, 2013, 11:15am UTC](https://forum.juce.com/t/shortcuts-dont-fire-application-commands/10411/6 "2013-05-07T11:15:56Z")

</div>

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