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);
Or register a callback to execute when specified key combination is pressed:
const keys = new PressedKeys();
keys.onKeys(["meta", "k"], () => {
console.log("open command palette");
});