App commands - KeyListener issue


#1

Okay, another quick-o thing that is probably from my desire to have my app easy to port to VST.

I have the “addKeyListener (commandManager->getKeyMappings ())” call happen in my MainComponent constructor. This works fine if I have clicked in the MainComponent area, but if I have, for example, maximised the window (and thus given the MainAppWindow focus), the key commands don’t work til i’ve clicked the main component.

This makes sense of course, as i’ve not given the keypresses to the top level window. I don’t want to have to keep stuff in the top level window though- as a VST plugin, the JuceAudioPlugin isn’t responsible for providing a TopLevelWindow, right? I tried to change it to

getTopLevelComponent ()->addKeyListener (commandManager->getKeyMappings ());

… expecting it to find the top level window (if there is one), but the same problem happens - clicking the title bar removes the shortcut key detection.

aren’t i a trouble maker today!


#2

hmm - when you call getTopLevelComponent(), that’s not by any chance in the constructor of your component, is it?.. If so, obviously it wouldn’t yet have a parent component to return…


#3

so simple! :smiley:


#4