browser-keyboard

Tracks which keys are currently held down, from the document's keydown / keyup events. Exposes the raw pressed keys plus selectors for codes, modifiers, and per-key checks.

Live example

Loading demo…

Press and hold keys — the on-screen keyboard reflects pressedCodesSelector live.

Install

bun add @valdres/browser-keyboard

Usage

import { useValue } from "valdres-vue"
import { pressedCodesSelector } from "@valdres/browser-keyboard"

const codes = useValue(pressedCodesSelector) // Ref<KeyboardCode[]>

Exports

ExportKindType
pressedKeysAtomatom (read-only)PressedKey[]
pressedCodesSelectorselectorKeyboardCode[]
pressedKeyValuesSelectorselectorstring[]
modifierSelectorselectorModifier[]
isCodePressedSelector(code)selector familyboolean
isKeyPressedSelector(key)selector familyboolean
toggleKeyAtom(key)atom family (settable)boolean

Cross-framework

Global atoms and selectors — works in every framework. For higher-level "press this combination → run this callback" hotkeys (rather than raw key state), use @valdres/hotkeys.