Skip to content

Use with AI coding agents

Coding agents build playable web games in minutes, but they almost never add controller support. Point one at llms.txt, a single page written for agents, and it can add it in one pass: which API to use in which situation, copy-ready recipes, the mistakes to avoid, and a test that runs without a controller.

Read https://gamepadly.com/sdk/llms.txt, then add controller support to this game with @gamepadly/sdk. Keep keyboard and mouse working, add haptics to the main game events, and write a test that runs without a controller.

This works for most games.

Read https://gamepadly.com/sdk/llms.txt. Make this keyboard game playable on a controller with the @gamepadly/sdk bridge (Recipe A). Do not change the game's input code. Check where it listens for keydown: if it is an element such as a canvas, pass it as keyTarget.
Read https://gamepadly.com/sdk/llms.txt. Build the input layer of this game with createActions() from @gamepadly/sdk so every action works on controller, keyboard and mouse.
Read https://gamepadly.com/sdk/llms.txt. Add haptics to hits, shots and pickups, and a "Connect controller" button that enables DualSense adaptive triggers through WebHID. The game must still work without it.
Read https://gamepadly.com/sdk/llms.txt. Map steering to the left stick and gas / brake to R2 / L2 as analog values, add the 'abs' trigger effect to the brake, and an engine rumble with createContinuous('engine').
Read https://gamepadly.com/sdk/llms.txt. Write Vitest tests for this game's controller support with createMockPlayerHandle() (Recipe D). They must run in Node without a browser.
File Contents
/sdk/llms.txt The agent guide: decision table, four recipes, haptic and button reference, rules and a “done when” checklist
Any page + .md Every docs page as Markdown, for example /sdk/start/add-controller.md
/sdk/llms-small.txt All guides in one file, without the API reference
/sdk/llms-full.txt Every page, including the full API reference

Every code block in these files is type-checked against the SDK source on each change, and the test recipes are run, so an agent copying them gets code that compiles against the current release.

If the agent will work on the game again later, add this to AGENTS.md, CLAUDE.md, .cursor/rules or your agent’s equivalent so it keeps the controller support intact:

## Controller support (@gamepadly/sdk)
- Reference: https://gamepadly.com/sdk/llms.txt
- One hub per page (`createGamepadly()`); dispose the hub, bridge, action maps and loops on teardown.
- Keyboard and mouse must keep working. The controller is added, not substituted.
- Bind buttons by position (`south`, `east`, ...); show labels with `getButtonLabel()`.
- Call `hub.connectWebHID()` only from a click. WebHID features are optional upgrades.
- Haptics go on game events (hit, shot, pickup), not on every key press.
- Controller tests use `createMockPlayerHandle()` and must keep passing.

The job is done when:

  • Keyboard and mouse still work exactly as before.
  • With a controller, movement, the main actions and pause work, and prompts show the right button labels.
  • A “Press any button” hint shows until a controller is detected.
  • Two or three game events trigger haptics.
  • Teardown disposes everything, and a test with createMockPlayerHandle() passes.

To try it by hand, open the game with a controller connected. To see what your controller reports, use the online controller tester.

Symptom Cause Fix
The controller does nothing The game listens on an element such as its canvas, and events dispatched on document never reach it Pass the element as keyTarget (details)
Nothing until a button is pressed Browsers hide controllers until the player presses a button Show a “Press any button” hint
The WebHID picker never opens connectWebHID() was called on page load Call it from a click handler
Trigger effects never apply They were set before WebHID connected Re-apply in hub.onCapabilitiesChange
Rumble keeps going or two hubs fight A hub was created per component or twice in React StrictMode One hub per page, disposed in the effect cleanup
Test sets state.buttons.south and nothing happens Mock state uses base names Use state.buttons.cross (south), circle (east), square (west), triangle (north)

More symptoms and fixes are in Troubleshooting.