Click triggered upon pressing Enter on keyboard- why?


#1

Hi People,

I am experiencing behavior I do not understand. I have two text buttons: ‘A’ and ‘Return’. I am assinging listeners to them and to ‘Return’ one I add keyboard shortcut (return key on keyboard).
It works as supposed, but in one scenario 2 buttons are triggered upon pressing return key.
When I first click on ‘A’ button and then use ‘Return’ button by pressing return on keyboard, it triggers both buttons.
Is this by design or it is kind of unexpected bug?
Thanks in advance for any hints!


#2

It’s easier to answer these types of questions if you post your code.


#3

It sounds like button A has keyboard focus so that’s what’s triggering that one, and then your Return button is triggered by your keyboard shortcut. The return key will simulate a click on button if it’s focused.

Have a look at the “Keyboard focus methods” section in juce_Component.h about how to control whether a component wants keyboard focus.


#4

This is it! Thank you, sir!