# Perspective mouse onClick not returning button value

**URL:** <https://forum.inductiveautomation.com/t/perspective-mouse-onclick-not-returning-button-value/53476>\
**Category:** Ignition\
**Created:** [November 25, 2021, 10:10pm UTC](https://forum.inductiveautomation.com/t/perspective-mouse-onclick-not-returning-button-value/53476 "2021-11-25T22:10:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![markrit](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/markrit/32/29635_2.png) [@markrit](https://forum.inductiveautomation.com/u/markrit)\
**Post date:** [November 25, 2021, 10:10pm UTC](https://forum.inductiveautomation.com/t/perspective-mouse-onclick-not-returning-button-value/53476/1 "2021-11-25T22:10:39Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/6/169dbef6074dd1297cc95cde1d1ef1611e7af5dc.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/b/bba1e3495305bbb1cab4a4e5ae381133f93f7aa6.png)

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 26, 2021, 7:39am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-onclick-not-returning-button-value/53476/2 "2021-11-26T07:39:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![markrit](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/markrit/32/29635_2.png) [@markrit](https://forum.inductiveautomation.com/u/markrit)\
**Post date:** [November 26, 2021, 4:33pm UTC](https://forum.inductiveautomation.com/t/perspective-mouse-onclick-not-returning-button-value/53476/3 "2021-11-26T16:33:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![markrit](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/markrit/32/29635_2.png) [@markrit](https://forum.inductiveautomation.com/u/markrit)\
**Post date:** [November 26, 2021, 5:14pm UTC](https://forum.inductiveautomation.com/t/perspective-mouse-onclick-not-returning-button-value/53476/4 "2021-11-26T17:14:12Z")

</div>

[https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/b/3bc6c920ef7f79fd045681179e8995d0f0535318.mp4](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/b/3bc6c920ef7f79fd045681179e8995d0f0535318.mp4)
  
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
```

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 27, 2021, 11:26am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-onclick-not-returning-button-value/53476/5 "2021-11-27T11:26:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![markrit](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/markrit/32/29635_2.png) [@markrit](https://forum.inductiveautomation.com/u/markrit)\
**Post date:** [November 27, 2021, 4:16pm UTC](https://forum.inductiveautomation.com/t/perspective-mouse-onclick-not-returning-button-value/53476/6 "2021-11-27T16:16:31Z")

</div>

Thanks. Mouse down event seems to work correctly

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [November 29, 2021, 4:42pm UTC](https://forum.inductiveautomation.com/t/perspective-mouse-onclick-not-returning-button-value/53476/7 "2021-11-29T16:42:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![markrit](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/markrit/32/29635_2.png) [@markrit](https://forum.inductiveautomation.com/u/markrit)\
**Post date:** [December 1, 2021, 12:08am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-onclick-not-returning-button-value/53476/8 "2021-12-01T00:08:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 1, 2021, 12:21am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-onclick-not-returning-button-value/53476/9 "2021-12-01T00:21:55Z")

</div>

[https://docs.inductiveautomation.com/display/DOC81/Perspective+Event+Types+Reference](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?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 1, 2021, 12:50am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-onclick-not-returning-button-value/53476/10 "2021-12-01T00:50:02Z")

</div>

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

> **[GlobalEventHandlers.oncontextmenu - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/oncontextmenu)**
>
> The oncontextmenu property of the
> GlobalEventHandlers mixin is an event handler that
> processes contextmenu events.

> **[GlobalEventHandlers.onclick - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onclick)**
>
> The onclick property of the
> GlobalEventHandlers mixin is the event handler for
> processing click events on a given element.

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