# Keylistener and Application Command Manager

**URL:** <https://forum.juce.com/t/keylistener-and-application-command-manager/18736>\
**Category:** General JUCE discussion\
**Created:** [August 15, 2016, 7:57pm UTC](https://forum.juce.com/t/keylistener-and-application-command-manager/18736 "2016-08-15T19:57:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [August 15, 2016, 7:57pm UTC](https://forum.juce.com/t/keylistener-and-application-command-manager/18736/1 "2016-08-15T19:57:55Z")

</div>

Is there any way of adding an applicationcommandmanager so it automatically listens for keypresses on all the windows I might open, some kind of global keylistener arrangement?

---

<div class="post-metadata">

**Author:** ![ed95](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ed95/32/7635_2.png) [@ed95](https://forum.juce.com/u/ed95)\
**Post date:** [August 16, 2016, 8:28am UTC](https://forum.juce.com/t/keylistener-and-application-command-manager/18736/2 "2016-08-16T08:28:09Z")

</div>

Hi bazrush,

The best way to do this is to declare and initialise an ApplicationCommandManager in your main application class and have a static function that returns a reference to it like this:

`static ApplicationCommandManager& getCommandManager();`

Then have your MainWindow class inherit from ApplicationCommandTarget and in its constructor get the reference to the ApplicationCommandManager using YourApplication::getCommandManager() and call registerAllCommandsForTarget (this) to register your MainWindow as a target. For an example of this, take a look at the Projucer code - the ApplicationCommandManager is declared in the ProjucerApplication class and the MainWindow class inherits from ApplicationCommandTarget and gets the command manager in its constructor to register itself as a target.

Hope this helps.  
Ed
