PressedKeys
Tracks which keys are currently pressed
Demo
Try and guess the password 👀
Usage
With an instance of PressedKeys
, you can use the has
method.
const keys = new PressedKeys();
const isArrowDownPressed = $derived(keys.has("ArrowDown"));
const isCtrlAPressed = $derived(keys.has("Control", "a"));
Or get all of the currently pressed keys:
const keys = new PressedKeys();
console.log(keys.all());