How to disable keyboard palm rejection in JavaScript

1 week ago 18
ARTICLE AD BOX

I'm building an FPS game in Three.js.

In my browser (Firefox, but happens on all my devices/browsers), when holding down any key at all, the cursor (pointer) locks up and gets extremely stiff.

This is annoying in my game, since when you try to walk (using the W key) and look around at the same time, the cursor gets stuck and you can't aim at anything.

I'm using the PointerLockControls script from here.

So, I tried creating my own PointerLockControls API from scratch to see if it was just the library or something with the browser:

let speed = 1; let PointerControls = { isLocked: true }; document.addEventListener("mousemove", function(event) { if (!PointerControls.isLocked || document.pointerLockElement != renderer.domElement) return; camera.rotation.order = "YXZ"; camera.rotation.y -= event.movementX / (500 / speed); camera.rotation.x -= event.movementY / (500 / speed); }); document.addEventListener("mousedown", function(event) { PointerControls.isLocked = true; renderer.domElement.requestPointerLock(); }); document.addEventListener("mouseup", function(event) { if (PointerControls.isLocked) return; PointerControls.isLocked = false; });

Still the same result. When walking (hold the W key), the cursor locks up.

I've also tried doing event.stopPropagation() and event.preventDefault() on document.onkeydown, but that also did nothing different.

After some research, I found out this is called palm rejection and that it's part of the OS.

Is there a way to disable this in JavaScript, and how?

Read Entire Article