If you’ve written a plain javascript webgame, it probably has this code somewhere:
var pressedKeys = {};
window.onkeyup = function(e) { pressedKeys[e.code] = false; }
window.onkeydown = function(e) { pressedKeys[e.code] = true; }
// on your game loop...
if (pressedKeys["KeyA"]) {...}In other words, transform the event-based browser input API into a state-based representation, which can be checked each frame. This is straightforward code, but I can’t find a library that implements this (and only this), so here’s a reusable version.

