addKeyListener issue

Hi all,

In the Juce “Plugin Host” demo, at the MainHostWindow’s constructor I see the following command :

addKeyListener (getCommandManager().getKeyMappings());

This key listener is called by keypressed() function of the corresponding component, assuming that the setWantsKeyboardFocus() function has prior been called.
But I can’t see any appropriate calling sequence to implement this issue
At this point I have lost the focus. . .
What am I missing about this ?

BTW with the code listed bellow :

enum AudioTreeCommands : juce::CommandID
open = 0x30000,
save = 0x30001,
etc. . .

I am experiencing the following problem : the enum items are not accepted as a legal parameter by the functions of AppliationCommandTarget class.
Any idea for this ?

Thanks in advance


Just a look from someone ?

Sorry, don’t understand your first question…

As far as the enums go, it does work if you set the type like that, you must be doing something else wrong. Maybe show an example of the way you’re using it?

About addKeyListener : What I mean is that no any call to setWantsKeyboardFocus() was made neither in MainHostWindow nor in any derived class, to indicate that the mainHostWindow needs keyboard focus.
Nevertheless, if I turn this command as a comment, any key presses (Ctrl-N. . .) has no any effect.
So, what I don’t understand is, where and when the setWantsKeyboardFocus() is called.

About enums : Ok I fixed it. I had declare enums inside a class by mistake

I think that if nothing wants the keypresses, they still get forwarded up to the top-level window for it to send them to the key mapping manager. Just because no specific component wants to use the keypresses itself doesn’t mean they should be thrown away.

Ok, it’s now completely clear.
Thanks a lot Jules.