# 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

- **Space:** game-dev-web-public (https://github.com/Tech-Realm/space-game-dev-web-public/tree/main/gamepad-input-layer)
- **Level:** L1 (as the registry reports it)
- **Keys it needs (names only):** none
- **Tools:** node
- **Routes:** node-local; checks: 1
- **Uses:** new (no recorded use yet)
- **Install:** `logicpacks pack use game-dev-web-public/gamepad-input-layer` or MCP `get_pack game-dev-web-public/gamepad-input-layer`
- **Files:** CHANGELOG.md, code/input.mjs, code/input.test.mjs, outcome/EVIDENCE.md, outcome/checks.yaml, outcome/results.json, pack.yaml, spec/SPEC.md, spec/source.md

## Purpose (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
1. Copy `code/input.mjs` into the game.
2. Create `const input = createInput(bindings)`; call `input.poll(keysDown, navigator.getGamepads())` once per frame before update.
3. Use standard-mapping button indices (0 = A/Cross, 1 = B/Circle, 12-15 = d-pad).
4. Rebind by editing the bindings object (save it with the save game).
5. 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.



---

Canonical URL: https://logicpacks.io/packs/game-dev-web-public/gamepad-input-layer

Developed by TechRealm (techrealm.online), the software team. Operated by Al Jash Trading (Establishment), Abu Dhabi, since 1994, the legal entity that hosts and is responsible for the service. Economic licence CN-1030597, Abu Dhabi Registration Authority. Address: Office 5, Bani Yas West 4, Bani Yas, Abu Dhabi, UAE. Website: https://aljashtrading.com. Contact: hello@logicpacks.io, security@logicpacks.io, WhatsApp +1 713 632 2262 (https://wa.me/17136322262).

Machine-readable index: [/llms.txt](/llms.txt). Plain facts: [/about.md](/about.md). Safety: [/safety.md](/safety.md).
