biodiv / contactjs

Pointer gestures for your webapp
MIT License
77 stars 6 forks source link

Restrict or detect which mouse button triggers events? #32

Closed AgileInteractive closed 1 year ago

AgileInteractive commented 1 year ago

When I add a Tap event, using mouse as input will trigger the event on all buttons (left-, middle-, right-click, even forward/back-clicks).

How do I limit the Tap listener to only be used on left-click?

jo-m1b commented 1 year ago

Same for me ! right-click is reconized by "press" event if i have tap and press on same element.

Maybe it could be great to have with the event :

Then we could deal with it like that :

domElement.addEventListener("contextmenu", event => event.preventDefault());

domElement.addEventListener("tap", function(event){
    if ( event.pointerType == "mouse" && event.button == 2 ) {
        //  do something
    }
});
AgileInteractive commented 1 year ago

Pixi.js has the same thing, where it solved it just like you suggest.

biodiv commented 1 year ago

You can access the original pointerEvent event using event.live.srcEvent.

I also added the recognizer option supportedButtons in v2.1.4:

const options = {
    "supportedButtons" : [2]
};

const tap = new Tap(rectangle, options);

This option can also be used for Pan and Press.

Be aware, that Tap uses pointerEvent.button instead of pointerEvent.buttons. The numbers differ between the two.

jo-m1b commented 1 year ago

hey ty ty a lot for this quick update !