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!

I quickly checked Cubase and Reaper because I’m in a similar situation. Turns out DAWs tend to implement some kind of a “catch all” solution for the enter key and break with this convention. Having to override every single button with a custom class is the same DRY issue like using setWantsKeyboardFocus. If the UI is not “fixed”, iterating over the whole hierarchy doesn’t appear to be the best solution either (I did exactly that for plugins with a fixed UI though, which turned out to steal the enter key from Cubase). If I find a safe and elegant solution I’ll post it here.

1 Like