# Double click on gui button

**URL:** <https://forum.babylonjs.com/t/double-click-on-gui-button/23053>\
**Category:** Questions\
**Created:** [August 13, 2021, 9:46am UTC](https://forum.babylonjs.com/t/double-click-on-gui-button/23053 "2021-08-13T09:46:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blackcatz19](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blackcatz19/32/16886_2.png) [@Blackcatz19](https://forum.babylonjs.com/u/Blackcatz19)\
**Post date:** [August 13, 2021, 9:46am UTC](https://forum.babylonjs.com/t/double-click-on-gui-button/23053/1 "2021-08-13T09:46:14Z")

</div>

Is it possible to capture double click event on gui button since I have came across only poirupen pointerdown pointerclick and pointermove events only.

---

<div class="post-metadata">

**Author:** ![wulf11](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wulf11/32/2196_2.png) [@wulf11](https://forum.babylonjs.com/u/wulf11)\
**Post date:** [August 13, 2021, 12:43pm UTC](https://forum.babylonjs.com/t/double-click-on-gui-button/23053/2 "2021-08-13T12:43:36Z")

</div>

There is no direct implementation that I am aware of, but you could implement your own “double-click-checker” function like this:

```auto
   // GUI
    var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
    var button = BABYLON.GUI.Button.CreateSimpleButton("myButton", "Click me");
    button.width = 0.2;
    button.height = "40px";
    button.color = "white";
    button.background = "green";

    //add PointerClickObservable to distinquish between single and double click
    button.onPointerClickObservable.add(() => {
        handleSingleDoubleClick();
    });

    advancedTexture.addControl(button);

    //simple vanilla js double click implementation taken from
    //https://stackoverflow.com/questions/5497073/how-to-differentiate-single-click-event-and-double-click-event
    var count = 0;
    function handleSingleDoubleClick() {
        if (!count) setTimeout(TimerFcn, 400); // 400 ms click delay
        count += 1;
    }

    function TimerFcn() {
        if (count > 1) console.log('you double clicked!')
        else console.log('you single clicked')
        count = 0;
    }

```

Here is a demo in the playground, needs some modification/customization, but maybe it gives you a point to start with 😄

[https://playground.babylonjs.com/#XCPP9Y#8636](https://playground.babylonjs.com/#XCPP9Y#8636)

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [August 13, 2021, 2:42pm UTC](https://forum.babylonjs.com/t/double-click-on-gui-button/23053/3 "2021-08-13T14:42:43Z")

</div>

Adding @msDestiny14 to maybe check if we can add dblClick?

---

<div class="post-metadata">

**Author:** ![msDestiny14](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/msdestiny14/32/9572_2.png) [@msDestiny14](https://forum.babylonjs.com/u/msDestiny14)\
**Post date:** [August 13, 2021, 5:06pm UTC](https://forum.babylonjs.com/t/double-click-on-gui-button/23053/4 "2021-08-13T17:06:40Z")

</div>

For some reason I could have sworn we either had double click or maybe I told someone how to do it once in a forum post. 🤔

How @wulf11 did it is exactly how I would have implemented it myself. Regardless I’m totally down to get it added in when I get a free moment 🙂 Would probably need some way to modify how fast the double click would have to be.

---

<div class="post-metadata">

**Author:** ![wulf11](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wulf11/32/2196_2.png) [@wulf11](https://forum.babylonjs.com/u/wulf11)\
**Post date:** [August 15, 2021, 5:20pm UTC](https://forum.babylonjs.com/t/double-click-on-gui-button/23053/5 "2021-08-15T17:20:23Z")

</div>

glad my solution seems to work ! 😄

guess you mean this post:

> [@Is there a way to create a double click event for BABYLON.GUI Buttons?](https://forum.babylonjs.com/t/is-there-a-way-to-create-a-double-click-event-for-babylon-gui-buttons/21594):
>
> I have been trying multiple ways to get this to work and had no success, is there a way to create a DoubleClick/DoubleTap observable for the BABYLON.GUI buttons that I am not seeing? I tried getting the information from the scene pointer events… this.getScene().onPointerObservable.add((pointerInfo, eventState) =\> { pointerInfo.pickInfo. switch (pointerInfo.type) { case BABYLON.PointerEventTypes.POINTERTAP: console.log("POINTER TAP"); …
