I placed a perspective button component on a view. I want to detect only mouse clicks, not enter presses. It appears that pressing the ENTER key and clicking with the mouse generates the same events.
I tested the behavior by creating and event script in the following 4 events:
I noticed that when the button has focus and I press the ENTER key it generates both a "onClick" and 'onActionPerformed' event. It does not generate a "onKeyDown" event. It will generate an "onKeyUp" event if I have the "onClick" and "onActionPerformed" actions disabled.
I would like to raise the "onClick" event ONLY when the mouse clicks the button, not when the enter button is pressed.
That's a good suggestion and I poked around for something to use as a filter in the MouseEvent. Unfortunately the MouseEvent does not have anything that appears to contain information about the enter key being pressed. I specifically tested the 'button' and 'buttons' event but these appear to be related only to the buttons on the mouse, not the keyboard. No other event seemed like it would contain enter button pressed details although I did not test every event.
event.detail and all coordinate properties will be zero on enter press. When it's a mouse click, event.detail will be 1, and all coordinate parameters will be relative to mouse cursor position (probably not zero).
I imagine the if statement I provided will work for your usage case exactly as it is written.
I would caution that this breaks what the majority of users will expect. Generally, users are going to expect a button with focus to behave the same regardless of if they click on it with a mouse or press the enter key.