Differenciate left click and right click

Hi,

a quick question, on a pointerTap babylon event there is a better way to differentiate left click and right click than by the inputIndex? If i’m right 2 = left click / 3 = mouseWheel click / 4 = right click ?

scene.onPointerObservable.add(pointerInfo => {
  switch (pointerInfo.type) {

    case BABYLON.PointerEventTypes.POINTERTAP: {
      
      // on left tap (left click)
      if(pointerInfo.event.inputIndex == 2){
        // do something
      }

      // on mouseWheel tap (mouseWheel click)
      if(pointerInfo.event.inputIndex == 3){
        // do something
      }

      // on right tap (right click)
      if(pointerInfo.event.inputIndex == 4){
        // do something
      }

      break;
    }

}

thanks by advance :slight_smile:

Hello @VerandaLouis , how are you doing?

You can use the pointerInfo.event.button property to get that information, where:
0 = left button,
1 = middle button
2 = right button

I’ve made a playground example should how to do it:
Babylon.js Playground (babylonjs-playground.com)

3 Likes

i’m fine thank you :smiling_face:

so it’s almost like pointerInfo.event.inputIndex except it’s a property directly so it’s cleaner haha.

Thank you for fast respond.

1 Like