Default Keyboard Focus for Buttons


Is there a particular reason why Button components listen to numpad enter ? This only happens on Windows. It turns out that WaveLab uses numpad enter to restart playback, and some power users use this functionality, so it’s one of those small things that can make a huge difference to a certain market share of users.

Ideally I don’t want any Components stealing keyboard focus unless they are explicit keyboard users. Of course it’s easy to set manually via Component::setWantsKeyboardFocus (false) but I’ve already gotten bitten with this DRY issue where I have buttons that are in a separate Component hierarchy and such that I forget to add the line of code for.

To reproduce, build the JUCE Demo app on Windows, click a button, then hit numpad enter . It will continue to toggle the last clicked button.


You could make your own button subclass that ignore keypresses, I guess, or just write an iterator that calls setWantsKeyboardFocus (false) for every component in a hierarchy.
But responding to return/enter keys is pretty normal button behaviour.


Ok thanks Jules for the explanation!