Perspective mouse onClick not returning button value

I have an onClick script that I want to return mouse button clicked. Always returns 0??? I also tried this script on the root container with same result. clientX and screenX both return values.

Its not the event.button that only return 0 (=left click)
it seems its only the left click that triggers the on click event

Yes seeing the same. If I set the label.text = 5. Then left click will set it to ‘0’ but right click & Center click do nothing


short video of clicking 3 times with left button and 3 times with right. The label above the blue button is displaying clientX, clientY, button.
code for the root container mouse.onClick >> Run Script

def runAction(self, event):

a = str(event.clientX) + ',' + str(event.clientY) + ',' + str(event.button)
self.getChild("Label").props.text = a

On context menu does detect right clicks, just gotta prevent the default so it doesnt open the menu. And do whatever you need to do to know which button was clicked

Thanks. Mouse down event seems to work correctly

1 Like

You are interpreting the “onClick” event to be a generic event which encompasses both left and right clicks, when “onClick” should actually be understood as “left click”, whereas onContextMenu should be used for right-click events.

Ok. So what is the purpose of the event.button and event.buttons in the Run action arguments?

https://docs.inductiveautomation.com/display/DOC81/Perspective+Event+Types+Reference

According to the manual, the onClick event occurs when any mouse button is clicked, the onContextMenu event occurs only when the right mouse button is clicked.

event.button indicates which mouse button initiated the event.

event.buttons is used in the cases where multiple buttons are pressed simultaneously and contain a sum indicating which buttons were held when the event occured.

Perhaps the documentation should be updated?

Mice can have more than one button. OSes can invert the behavior of left and right mouse buttons.

These are global JS event handler hooks, not something Perspective adds or is in charge of.