How to reduce keyboard input latency

Everyone says that the keyboard input delay in web browsers is usually around 10ms to 30ms.
I am aiming for a response speed lower than that to use this to move objects in three.js or start other calculations.

The way I thought with my poor head was:

Web HID API
Web Worker + SharedArrayBuffer
requestIdleCallback
GPU acc

Does anyone have any other good methods or examples?

there’s no input lag as far as i know, just like as i type now i don’t see or feel one. on mobile yes but i have never seen this be a problem on a desktop browser with keyboard input.

1 Like

Most likely you are aiming at the wrong target to optimize.

Whenever I experience keyboard lagging in my Three.js programs, it has always been caused by heavy renderings or event listeners running for too long. The keyboard event handling has always been innocent. It is my code that makes it appear sluggish.

1 Like

Another pitfall is trying to perform too much work in event handlers. Event handlers can sometimes fire at higher frequencies than the app is rendering, which compounds the load of stuff you do in them.

Event handlers should really just record events, and leave the processing of them to happen in the renderloop.

1 Like

Hardcore rhythm gamers notice even a 2ms error and complain. I don’t think we should think about it from our perspective. :frowning:

Events onKeyDown and onTouchStart are immediate, and their subsequent release is associated with confirmation. Peripheral controllers are designed with minimal latency. What is fair? There is no groundbreaking technology to develop. Some cameras have an API for 240fps, 960fps if you’re at a wired location playing DDR or Fruit Ninja or Beat Sabre.

1 Like