How to detect right click + left click

后端 未结 6 713
感动是毒
感动是毒 2021-01-13 19:22

I am building a game

And I need to do something when the user clicks on the right mouse button, holds it and then presses the left button

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-13 19:58

    Use MouseEvent.buttons in your event handler.

    .addEventListener("mousedown", function(event){
        if ((event.buttons & 3) === 3){
            //Do something here
        }
    }, true);
    

    It is kinda recent though, you may want to implement fallback method, recording state of mouse buttons.

提交回复
热议问题