True while a Windows / Meta (Cmd) key is held — controllers can gate movement on this.
True if the given KeyboardEvent.code is currently held.
True if any of the given codes is currently held.
Inject a key as if it were physically pressed. Use when the controller is attached after the real keydown already fired (e.g. a double-tap toggle).
Release a single key programmatically.
Forget all held keys.
Register the document / window listeners. Idempotent.
Remove the listeners and clear all held keys. Idempotent.
Robust held-key tracker for keyboard-driven controllers.
Maintains a Set of currently-held
KeyboardEvent.codevalues and — the whole point of this class — recovers from the cases where the browser never delivers the matchingkeyup, which would otherwise leave a key stuck "down" forever so the camera / player keeps moving after you let go:blur.visibilitychangewhendocument.hidden.keyup. Browsers also famously omitkeyupfor other keys while a Meta key is held. We clear everything on any Meta release as a catch-all, and expose metaHeld so controllers can ignore movement while the combo is in progress.keydownis ignored while a text input / textarea / contenteditable is focused so the player's typing isn't read as movement.keyup, by contrast, is ALWAYS processed regardless of target — clearing a key that isn't held is harmless, and unconditionally honoring releases avoids a key sticking when focus moved between the press and the release.