Respond to mouse movement when a key is pressed (Javascript, jQuery)

Edit: It seems the problem is with the touchpad, not the mouse.

Purpose: To respond to mouse movements even when you press keys.

I want to change the PointerLockControls of Three.js so that: if the user clicks the mouse while pressing "W", the camera should continue to move forward, and the direction of the camera should also change in accordance with the movement of the mouse. This does not occur in a normal scenario. Here are the listeners:

Listener for the 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;
}

, "W", . , ( ).

+5
1

. .

+2

All Articles