/dm-game:input-bindingsfrom dm-game
The input layer of a browser game: an action map on KeyboardEvent.code, key remapping ('press a key…', Esc cancels, swap on conflict with a notice and undo, reset), reserved keys, merging newly added actions into an old save, gamepad polling with edge detection and deadzones, button prompts that follow remaps and the last-used device, and hold/toggle options. Use when adding controls, a remap screen or gamepad support; when on-screen key hints are hard-coded; when a new action ships and old saves must keep working; or when players say 'I can't rebind that', 'the hint says F but I changed it', 'WASD is wrong on my AZERTY keyboard', 'my controller doesn't work', 'two actions are on the same key', or 'the prompt shows keyboard keys while I'm on the pad'. Owns bindings and prompts; settings-and-persistence owns storing them.
Ships in dm-game. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Purpose: Every action is remappable, prompts always show the binding that actually works, the game reads the pad as reliably as the keyboard, and an update that adds an action never breaks a player's saved controls. Touch is a third device for the same actions; its sticks and failures are touch-controls'.
Sources:
KeyboardEvent.code is the physical key, layout-independent; never
derive a label from it.navigator.keyboard.getLayoutMap() gives labels, but it is experimental and
Chromium only.getGamepads() each frame; the "standard" mapping indices;
no pads are exposed until a pad gesture.mergeBindingsKeyTagTyped sketch: references/bindings.ts, with pure rebind, undo and merge functions.
| Failure | Seen in | Root cause |
|---|---|---|
| Key hints wrong after a remap | logarithmic | [F] BUY hard-coded in HTML and HUD strings |
| Old save plus new action leaves the new action unbound, or sharing a key | timberwolf (fixed by mergeBindings) | Save loaded over defaults without re-checking collisions |
| Duplicate binding wipes every binding | logarithmic | Sanitiser resets the whole keymap on any duplicate |
| Bindings follow the label, not the key position | timberwolf | Stored e.key, so AZERTY players get WASD in the wrong places |
| No way back to defaults | timberwolf | No reset |
| Pad only in help text | redshifted | Pad bindings rendered as a static guide |
| Pad couldn't unpause | Hard Deck (fixed) | Polled inside the sim tick |
Gameplay asks isDown('fire') and pressed('jump'), never e.code === 'Space'.
An action has:
press (edge) or hold (level, with an optional toggle mode)codesThis one indirection is what makes remapping, prompts, toggles and pad support possible without touching gameplay.
Presses reach the fixed-step sim through a latch. Key and pad edges arrive per rendered frame, and the sim ticks at 60 Hz. A press is latched until a tick consumes it:
Holds are sampled at each tick, not latched. The latch is cleared with held input
whenever game-shell opens a screen (PressLatch in the sketch).
Scope of remapping. Gameplay actions are fully remappable. Menu navigation stays fixed and always available: arrows, Enter and Esc, plus the D-pad, A, B and Start. A remap can never strand the player in a menu. Menu actions may take additional keys. This is a deliberate, partial deviation from XAG 107's "remap all controls"; say so on the Controls screen.
code, show the layout labelKeyboardEvent.code (KeyW), never key (w, which is
z on AZERTY). Defaults are then positional, WASD on any layout, and
case-insensitive for free.navigator.keyboard.getLayoutMap() where it exists, so KeyW
reads as "Z" for an AZERTY player.
KeyW → "W").While a slot is capturing, the key goes to capture inside game-shell's
keyboard router. That is the single capture-phase keydown on window, and
"capturing?" is its first check. It calls preventDefault() and
stopImmediatePropagation(), then resolves the capture.
preventDefault() alone doesn't stop other listeners. Gameplay and menu
listeners also ignore keys while shell.ownsInput.cancelCapture() for those, and hands every other key or button to capture.
They are the only inputs capture can't bind.pad()). The A press
that started a pad capture was consumed in that frame and can't bind itself.click, not pointerdown. Otherwise the press that opened
the slot is captured as a mouse binding.e.repeat. Holding a key as capture starts must not bind it by
accident.Binding key K to action A, where B already holds K:
Esc: game-shell's back and pause.
Browser and OS keys the page can't or shouldn't take:
Refuse them with the reason shown.
Tab is not reserved. Menus own input while they're open, so Tab is free for
play. Keep HUD buttons out of the tab order with tabindex="-1" (menu-navigation
rule 5).
The gameplay key handler calls preventDefault() on every bound key while the
stack is empty. Otherwise Tab's default moves focus out of the page, which
blurs the window and pauses the game. Space would scroll; arrows would scroll
too.
Pad Start: it toggles pause and cancels a pad capture.
The pause action can't take a key menus need (Enter, Space, Tab, the
arrows). Pause works from inside menus, so binding it there would break every
menu. rebind refuses those keys for pause, with the reason shown. A swap that
would push pause onto one gives it a spare instead, and the loader treats a
saved menu key for pause as unbound-to-default.
Debug keys used in development builds, such as Backquote (abduction-run).
Poll navigator.getGamepads() once per rendered frame. Entries can be null.
Keep the last frame's buttons to compute edges (pressed/released this frame).
A pad gets no repeat flag, so edges are the only fresh-press signal.
mapping === 'standard' means the W3C layout:
Anything else, show "Unrecognised controller: check the pad bindings" and let the player remap by raw index.
Deadzone: radial, rescaled so output starts at 0 at the edge of the deadzone. Starting value 0.15–0.2, the default range accessibility-design quotes; adjustable in settings. Test: a resting pad reads exactly 0 on the player's controller; a slight push moves the cursor. If the character drifts at rest, raise it.
Triggers are analog buttons (.value). Use press and release thresholds with
hysteresis. Starting values: press at 0.5, release at 0.4 (posture B). Test:
half-pulled triggers don't chatter. If they do, widen the gap; if a full pull
feels late, lower the press threshold.
Pad remapping captures the next button that goes from up to down in a poll. Start cancels: it's reserved. Esc on the keyboard cancels too. Every other button, B included, binds on its press edge. The prompt says "Press a button… (Start to cancel)" (XAG 112).
Disconnect is game-shell's: gamepaddisconnected feeds the auto-pause latch.
Pads only appear after a pad button press, which is normal.
prompt(action). It returns the label for the
last-used device: the key label, or the pad glyph.grep the source for
[F], "Space" and Press E as a check (logarithmic's stale hints).pad.id. Default to one family and offer a setting.Mouse-look and stick-aim sensitivity is a multiplier (split per device if the game needs it), stored in the
settings record (input.sensitivity). XAG 107 asks for at least ±50%. The virtual
cursor and camera read it live (see pointer-lock).
Every hold action offers Toggle (accessibility-design Tier 1; XAG 107 says avoid
long holds). In toggle mode, a press flips the state. Clear toggled state wherever
held keys are cleared: on game-shell opening a screen, and on window blur.
A verb that completes after a hold (hold G to board, hold T to cut a tow) must say
how long is left. The operator, ice-pirates playtest 2026-10-12: holding a key "should show
a progress bar on the key indicator to help inform when it will be done (this is
a typical game design pattern)". ice-pirates src/sim/hud-model.ts and
src/ui/hud.ts (commit 08de850) do it this way:
{ key, text, hold: 0..1 | null, action }.
hold is null for a tap and the progress for a held verb. The key comes from
prompt(action) (rule 8). ice-pirates still hard-codes "G" and "T", its own
noted gap.holding(action)
callback, so the model stays pure. ice-pirates checks the key only; it has no
toggle yet. Its hold value is derived partly from distance, so drawing it while
nothing runs would show progress the player isn't making.max(0, held) / needed. In ice-pirates, T
is both tap-to-lasso and hold-to-release, so the tow timer goes negative after a
release until key-up and that same hold can't start a lasso. Clamp it at 0 for
the bar.Felt verdict pending: the operator hadn't played the build yet when this was written.
blur and on every screen open (abduction-run
daedb89c; game-shell rule 1).code ShiftLeft and so on.
They are bindable, but Ctrl+W closes the tab: don't make Ctrl part of a default.
Free-horses whitelists keys and excludes Shift.e.isComposing, key === 'Dead'). Ignore them in
capture.Each line names what the check cannot see.
Unit, pure functions (rebind, undo, mergeSaved):
- swapping keeps every action bound
- undo restores the previous map exactly
- an old save plus a new action leaves no collision
- a corrupt duplicate falls back per action
Mutation-check: remove the swap and a test must fail. *Blind to: DOM event
order.*
Real browser, real keys: remap Jump to Space while Fire holds Space. The notice names both, and Undo restores. Rebind Jump's empty second slot to Fire's only key; Fire gets a spare, and the notice says so. Esc during capture cancels without opening pause. Blind to: other keyboard layouts unless the OS layout is switched.
AZERTY: switch the OS layout. Movement stays positional, and labels read
Z/Q/S/D where getLayoutMap exists. Blind to: browsers without the
Keyboard API, which show the QWERTY fallback.
Prompt sweep: grep for literal key names; then remap every action and read every screen with a prompt. Blind to: prompts built in places the grep pattern doesn't match.
Pad: plug in and press a button; prompts switch. Wiggle the mouse; they don't switch back. Click; they do. Blind to: non-standard pads, and other brands' glyphs.
Hold/toggle: toggle sprint on, open pause, resume. Sprint is off, not stuck on.
Three tight links. Everything else routes through the map, so adding a skill
touches one file rather than twenty: references/routing-map.md (in
game-design).
What SKILL.md sets; muted values are Claude Code's defaults
40 skills in this plugin
/accessibility-designUse when designing any player-facing feature, evaluating a game for accessibility, responding to accessibility feedback, designing difficulty or assist options, adding subtitle/caption systems, implementing input remapping, or when a player reports they can't play. Covers the four accessibility pillars (visual, auditory, motor, cognitive), implementation tiers, colorblind design, subtitle standards, input accessibility, and testing methodology. Accessibility is a design discipline, not a post-launch checklist./async-and-socialSocial and competitive design that does not require players to be online together: ghost/replay data, leaderboards, asynchronous PvP, offline vulnerability, and anti-snowball mechanics. Use when adding leaderboards or high-score tables, designing ghost races or replay challenges, letting players attack or compete against absent opponents, deciding what social signal a single-player game should carry, or when matches and runs feel decided in the first minutes. Anti-snowball applies to single-player roguelikes and simulations too, not just PvP. For real-time multiplayer architecture, matchmaking, guilds, and moderation, this skill deliberately does not cover them — those are large specialities and belong in dedicated references./audio-designUse when designing how audio communicates game state, creates emotion, and serves as a feedback system. Activate for sound effect design, adaptive music systems, spatial audio, ambient soundscapes, audio priority and ducking, emotional audio design, and audio accessibility. Also activate when audio feels disconnected from gameplay, when players routinely play on mute (a design failure signal), when evaluating whether the audio stack has appropriate layering and variation, or when planning how music responds to gameplay context. This skill treats audio as a design system — not audio engineering or production, but the intentional design of what players hear, when, and why. Covers the full audio stack from music and ambience through sound effects, UI audio, and voice./camera-controlControlling a 2D or top-down game camera, not juicing it: a pure 'where it wants to be' target kept separate from 'how it gets there'; exponential damping versus a critically damped spring, with halflife as the tuning unit; velocity look-ahead and an aim lead on its own slow clock; zoom as a product of named factors (player base zoom, wheel, screen size, speed); combat framing that zooms out to keep every threat on screen, with a floor; an optional rotate-with-ship (heading-follow) mode and what it does to the HUD; shake applied only at render and never to the aim; one pair of world/screen conversions; and the camera options players expect. Use when building or reviewing a follow camera, adding zoom or a camera options tab, or when players say 'the view jumped when my mouse came back', 'I got shot from off screen', 'I can't see far enough ahead', 'the zoom makes me sick', 'it's too floaty' or 'too stiff', or 'the arrow points the wrong way'. Shake, punch and the trauma budget are game-feel's./cosmic-horror-registerTone, diction, and sensory palette for cosmic-horror game narrative — Lovecraftian, weird-fiction, eldritch, Arkham-adjacent, deep-time or deep-space dread. Use when writing or reviewing in-game text, story bibles, item descriptions, or interstitials for a cosmic-horror game; when horror prose reads as generic spooky rather than cosmic; when the mystery is being over-explained; or when a draft is leaning on words like eldritch, unspeakable, or indescribable to do the work. Also the worked example of the six-slot register template — read the Register template section to build folk-horror, noir, comic, or any other tonal register the same way. Layers on top of game-narrative-craft, which supplies the structural rules; this skill supplies only tone./data-driven-designTelemetry and analytics for games: event taxonomy and schema, engagement/progression/economy/balance/UX metrics, funnel analysis, A/B testing and when not to, cohort analysis, dashboard design, and the interpretation traps — Goodhart's Law, Simpson's paradox, survivorship bias, over-optimisation. Use when instrumenting a game, deciding what to measure, reading a retention or funnel drop, comparing cohorts, or when a metric moved and you need to know whether it means anything. Data-informed, not data-driven: numbers say what happened, not why. For pre-ship qualitative evidence use playtest-design.npx claudepluginhub rbergman/dark-matter-marketplace --plugin dm-game