Check if PointerEventTypes.POINTERTAP comes from left or right mouse button

BABYLON.PointerEventTypes.POINTERTAP is triggered independently if the user clicked in a mobile device, or a computer, that’s ok but there is any chance to know if the user pressed left or right mouse click on PC?

Thank you in advance.

It seems these PointerEventTypes are not available yet in the Babylon API.
You could use the event.button-property:

 scene.onPointerObservable.add((pointerInfo) => {
		switch (pointerInfo.type) {
			case BABYLON.PointerEventTypes.POINTERTAP:
                switch (pointerInfo.event.button) {
                    case 0: 
                        console.log("LEFT");
                        break;
                    case 1: 
                        console.log("MIDDLE");
                        break;
                    case 2: 
                        console.log("RIGHT");
                        break;
                }
            break;
        }
    });

Consider that event.which property also works, but is deprecated!

3 Likes

It seems that pointerInfo.event.button returns a number but thank you so much!

Did you try the provided code above? :thinking:

Thats why I used a switch clause :wink:
You have to interpret the returned numbers with some sort of condition!

The PointerEventTypes are also just static constants, containing a number (like Enums)

1 Like

Sorry my bad! I just copied pointerInfo.event.button and compared with “LEFT” :roll_eyes:

1 Like