Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Respond to mouse movement when key is being pressed

Edit: Looks like the problem is for touchpad not mouse.

Goal: To be able to respond to mouse movements even when key(s) is being pressed.

I want to modify PointerLockControls of Three.js so that: if user moves mouse when pressing W, then the camera should continue to move forward and the direction of camera should also change according to mouse movement. This is not happening in normal scenario. Here are the listeners:

Listener for mousemove event:

var onMouseMove = function ( event ) {
    var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
    camera.rotation.y-=movementX*0.002;
  };

Listener for keydown event:

var onKeyDown = function ( event ) {
    
        case 38: // up
        case 87: // w
            moveForward = true;
            break;
        //keys: a, s, d are handled similarly

        case 32: // space
            if ( canJump === true ) velocity.y += 10;
            canJump = false;
            break;
   }

Listener for keyup event:

var onKeyUp = function(event){
        case 38: // up
        case 87: // w
            moveForward = false;
            break;
}

I found that, if I hit spacebar when pressing W, then, the player continues to move forward AND responds to mouse movement. This is the effect I want (but it should work even without hitting spacebar).

like image 569
coolscitist Avatar asked Nov 04 '22 01:11

coolscitist


1 Answers

Usually Operating Systems disable the touchpad when typing. You should find an option to toggle this somewhere on your OS settings.

like image 163
mrdoob Avatar answered Nov 12 '22 18:11

mrdoob