Packs / game-dev-web-public
gamepad-input-layer
Merge keyboard and gamepad input into one action map (move, jump, fire) with dead zones, edge detection (pressed this frame) and rebinding, as a dependency-free ES module
Install
logicpacks pack use game-dev-web-public/gamepad-input-layerget_pack game-dev-web-public/gamepad-input-layerThe second line is the MCP tool call for the LogicPacks connector (Claude Code, Codex, Claude.ai and others). The first run of a pack someone else wrote asks for your yes.
Keys it needs (names only)
None.
Playbooks included
- Spec:
spec/SPEC.md(goal, steps, edge cases, don’ts) - Routes:
node-local - Checks: 1 in
outcome/checks.yaml - Code:
input.mjsinput.test.mjs - Tools: node
Usage, last 8 weeks
New: no recorded use yet.
Purpose (from spec/SPEC.md)
Goal
Game code asks input.down('jump') / input.pressed('fire') / input.axis() and never cares whether a key or a controller was used.
Steps
- Copy
code/input.mjsinto the game. - Create
const input = createInput(bindings); callinput.poll(keysDown, navigator.getGamepads())once per frame before update. - Use standard-mapping button indices (0 = A/Cross, 1 = B/Circle, 12-15 = d-pad).
- Rebind by editing the bindings object (save it with the save game).
- Check:
node code/input.test.mjs.
Edge cases
- Stick drift: radial dead zone (default 0.2) and rescale to 0..1 outside it.
- Non-standard mapping (
pad.mapping !== 'standard'): show a remap screen.
Don'ts
- Don't read input inside event handlers for gameplay (frame-inconsistent).
- Don't assume pad index 0 is the active one: use the last one with input.