How to detect right click + left click

后端 未结 6 714
感动是毒
感动是毒 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 20:14

    Try

    var hold=false;
    
    function check(e) {
      if(e.button==2) hold=true;
      if(e.button==0 && hold) console.log('action');
    }
    
    function release(e) {
      if(e.button==2) hold=false;
    }
    
    function noContext(e) { e.preventDefault(); }
    .box { width: 100px; height: 100px; border: 1px solid black;}
    Hold right mouse button and press left (on sqare)
    

提交回复
热议问题