# Can onDragStartObservable capture what mouse button is used?

**URL:** <https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030>\
**Category:** Questions\
**Created:** [May 4, 2022, 7:50pm UTC](https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030 "2022-05-04T19:50:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![opeologist](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/opeologist/32/23118_2.png) [@opeologist](https://forum.babylonjs.com/u/opeologist)\
**Post date:** [May 4, 2022, 7:50pm UTC](https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030/1 "2022-05-04T19:50:56Z")

</div>

there’s a known issue i’m trying to resolve when using Firefox and/or Safari that triggers a created onDragStartObservable on a mesh in our scene when the right mouse button is used. traditionally, most don’t drag with the right mouse button, so i’m wondering if there’s a way to determine what button is contributing to firing the observable, so we can ignore any triggers from the right mouse button? the callback event argument doesn’t supply any information related that i can tell. if this isn’t available, how trivial or otherwise would it be to add? thanks!

to add color to the situation, it looks like on Chrome the dragStart fires as well, but _immediately_ fires dragEnd after the dragStart observable completes, which “simulates” it working as intended, but my expectation is that the right button mouse shouldn’t fire any drag events.

---

<div class="post-metadata">

**Author:** ![CLB\_ZReality](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/clb_zreality/32/4293_2.png) [@CLB\_ZReality](https://forum.babylonjs.com/u/CLB_ZReality)\
**Post date:** [May 4, 2022, 8:21pm UTC](https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030/2 "2022-05-04T20:21:05Z")

</div>

Hi there. At first i was thinking you could get it via event.pointerId . But unfortunately the pointerId seems to be always 1 in this event regardless if the left, right or middle mouse button is clicked. I have coded a kind of solution for your problem anyways in this playground: [https://playground.babylonjs.com/#0SLSCF#6](https://playground.babylonjs.com/#0SLSCF#6)

Might not be the best, but it does the trick. Hope i could help 🙂

---

<div class="post-metadata">

**Author:** ![opeologist](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/opeologist/32/23118_2.png) [@opeologist](https://forum.babylonjs.com/u/opeologist)\
**Post date:** [May 4, 2022, 8:57pm UTC](https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030/4 "2022-05-04T20:57:46Z")

</div>

@CLB_ZReality well actually, trying the playground on Firefox still drags when right clicking on the mesh… so, i don’t think the issue is with checking for a right button click within the observable… the issue seems to stem for _any_ mouse button click starting the drag behavior

i added `window.addEventListener('contextmenu', (evt) => evt.preventDefault());` to the top of the createScene function to eliminate the native browser context menu from appearing, and you can still right click and drag the box.

ref: [https://playground.babylonjs.com/#0SLSCF#7](https://playground.babylonjs.com/#0SLSCF#7)

this seems like something that might need tweaks within babylon’s internals, as adding the drag pointerBehavior applies it to any button click, and still starts the drag of the element, regardless of a check within the observable…

---

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)\
**Post date:** [May 5, 2022, 4:14am UTC](https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030/5 "2022-05-05T04:14:58Z")

</div>

What about enabling/disabling the dragging behavior based on which button was pressed?

> **[Babylon.js Playground](https://playground.babylonjs.com/#0SLSCF%2311)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![opeologist](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/opeologist/32/23118_2.png) [@opeologist](https://forum.babylonjs.com/u/opeologist)\
**Post date:** [May 5, 2022, 5:14am UTC](https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030/6 "2022-05-05T05:14:52Z")

</div>

that might just do it! i’ll check in the morning. thanks a bunch!

---

<div class="post-metadata">

**Author:** ![CLB\_ZReality](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/clb_zreality/32/4293_2.png) [@CLB\_ZReality](https://forum.babylonjs.com/u/CLB_ZReality)\
**Post date:** [May 5, 2022, 3:46pm UTC](https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030/7 "2022-05-05T15:46:44Z")

</div>

Blake’s answer seems to work for me 🙂

In my solution i didn’t get that you meant, the mesh should actually not be able to be dragged anymore. I just thought you don’t wanted the onDragStartObservable to execute it’s code.

---

<div class="post-metadata">

**Author:** ![opeologist](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/opeologist/32/23118_2.png) [@opeologist](https://forum.babylonjs.com/u/opeologist)\
**Post date:** [May 5, 2022, 3:47pm UTC](https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030/8 "2022-05-05T15:47:23Z")

</div>

yeah, thanks a bunch for showing that solution though! should help if others need that 😃

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [May 6, 2022, 12:33am UTC](https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030/9 "2022-05-06T00:33:24Z")

</div>

Maybe @PolygonalSun can help.

---

<div class="post-metadata">

**Author:** ![PolygonalSun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/polygonalsun/32/2704_2.png) [@PolygonalSun](https://forum.babylonjs.com/u/PolygonalSun)\
**Post date:** [May 6, 2022, 7:43pm UTC](https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030/10 "2022-05-06T19:43:46Z")

</div>

As there’s no way to distinguish what button is being pressed inside of the onDragStartObservable, using @Blake’s solution is a good approach. I do feel like it’d be important to have a button’s context available inside of the observable though. Lemme see if I can think of any way to get this from the current `PointerDragBehavior` object.

---

<div class="post-metadata">

**Author:** ![PolygonalSun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/polygonalsun/32/2704_2.png) [@PolygonalSun](https://forum.babylonjs.com/u/PolygonalSun)\
**Post date:** [May 9, 2022, 5:17pm UTC](https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030/11 "2022-05-09T17:17:48Z")

</div>

I was unable to find any good way to get the button pressed by directly using anything within the `PointerDragBehavior` object. Since the initial intent was to limit certain buttons from initiating the drag, I created a PR to allow the user to specify which buttons can be used: [Fix PointerDragBehavior to account for button context, add button filter by PolygonalSun · Pull Request #12499 · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/pull/12499)

---

<div class="post-metadata">

**Author:** ![opeologist](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/opeologist/32/23118_2.png) [@opeologist](https://forum.babylonjs.com/u/opeologist)\
**Post date:** [May 11, 2022, 6:12pm UTC](https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030/12 "2022-05-11T18:12:21Z")

</div>

thanks so much for the PR! this will definitely improve the expectations when using the behavior 😃 can’t wait for the release!

---

<div class="post-metadata">

**Author:** ![PolygonalSun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/polygonalsun/32/2704_2.png) [@PolygonalSun](https://forum.babylonjs.com/u/PolygonalSun)\
**Post date:** [May 11, 2022, 6:44pm UTC](https://forum.babylonjs.com/t/can-ondragstartobservable-capture-what-mouse-button-is-used/30030/13 "2022-05-11T18:44:27Z")

</div>

The PR has been merged so the changes should be available in version 5.5.7 when it’s released.
