The keyboard can be an instrument.
Guitoro maps one side of a computer keyboard to chords and the other side to strums, picking, mutes, and song controls. It also accepts touch and mouse input. Its public guide says the keyboard map follows physical positions on a United States QWERTY layout.[1]
That turns a familiar input device into a two-handed control surface. It also exposes every choice a keyboard-heavy web interface has to make. Does the app care about the character printed on a key or its physical position? What happens when two keys are held? Who owns the key when a text field has focus? What releases a visual state if the window loses focus?
A shortcut is a moment. An instrument is a state machine.
Choose position or meaning.
KeyboardEvent.code names a physical key position. MDN uses game controls as its main example because the same physical cluster can stay useful across keyboard layouts. The printed character can differ. A position reported as KeyQ on a QWERTY keyboard may carry another label on Dvorak or AZERTY.[2]
KeyboardEvent.key reports the key value after the keyboard layout and modifier state are applied. Use it when the character matters. Use code when the physical arrangement matters. If you choose physical positions, show the actual control labels and document the layout assumption. Do not tell an AZERTY user to press a printed Q when the app is listening for the physical position.
Track press and release.
A one-shot shortcut can act on keydown. A held control needs both keydown and keyup. MDN recommends that game-like controls start motion on press and stop on release instead of depending on operating-system key repeat. That also permits simultaneous controls.[2]
Keep a set of active keys. Ignore repeated keydown events for keys already in the set. Remove each key on keyup. Clear the set on window blur so a released key does not remain visually stuck after the tab loses focus.
Focus is the first interlock.
Global listeners make demos feel immediate, but they can steal letters from forms, editor surfaces, browser commands, and assistive input. Give the control a focusable housing. Act only while that housing owns focus. Leave Tab, Escape, system shortcuts, and text fields alone.
Mouse and touch users still need visible controls that perform the same actions. Native buttons supply focus, activation, and labels without recreating those contracts. The soundcheck below uses four buttons and an optional keyboard layer. The visual state works when Web Audio is unavailable.
Sound starts after consent.
MDN summarizes browser autoplay policy as creating or resuming an audio context inside a user gesture. It also recommends clear play, stop, volume, and mute controls for pages that make sound.[3]
The bench therefore starts silent. The arm button creates or resumes its audio context. Disarming it stops sound without disabling the visible pads. No key press outside the focused playfield produces a note.