Keylistener and Application Command Manager


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?


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.