I have a main component, with a main menu and some keyboard shortcuts associated to it (like ctr-c for copy, ctrl-z for undo, and so on …)
I noticed that they work only until I click on another component, then, by default the other component takes the focus, because in internalMouseDown, there’s this code
[code] if (! flags.dontFocusOnMouseClickFlag)
{
grabFocusInternal (focusChangedByMouseClick, true);
if (checker.shouldBailOut())
return;
}
[/code]
I would like my main menu shortcuts to work, whatever component has the keyboard focus. Is there a way to do that ?
The other option would be to set the ‘dontFocusOnMouseClickFlag’ to true for every other component but that’s tedious and I guess that would prevent text entry on some text fields …
Hi dinaiz,
Well yes you have that facility in JUCE… You just need to implement the class ApplicationCommandTarget in your main menu… You will need to implement its 4 pure virtual methods and then call the handleCommandMessage of whatever component you want to perform the action in… A small example implementation for refresh = F5:
Thank you very much ! I totally forgot to say I solved the problem. I did what you say in your post, however I had another keyboard listener in the application who returned always true, so the keypresses where never reaching the ApplicationCommandTarget. Now it’s solved. Thanks for your kindness !