One Free Prompt Adds Full Controller Support to a Browser Game
One long prompt makes an AI coding tool add full gamepad support to your browser game.
How to use
- Open your game folder in Claude Code or another AI coding tool.
- Paste the prompt.
- Wait for the AI to list inputs and screens.
- Play the whole game with only a controller.
Add full gamepad support to this browser game. A player with only a controller must be able to do everything a keyboard and mouse player can: start the game, change every setting, play, pause, type a name, and get back to the title screen. Keyboard and mouse must keep working exactly as before.
First, read the code and write down two lists:
1. Every input the game uses: each key, mouse button, mouse move, click and hover, and what it does.
2. Every screen and popup: title, menus, settings, pause, game over, dialogs, text fields, and anything that only shows on hover.
Every item on both lists needs a gamepad way to reach it. Don't skip any.
Reading the controller:
- Use the browser Gamepad API. No new libraries.
- Call navigator.getGamepads() every frame, also while paused and in menus. Don't keep the Gamepad object from the gamepadconnected event, it goes stale.
- Use the first connected pad that has pressed a button. Handle a pad plugged in or unplugged at any time. Browsers only report a pad after a button press, so the game must not need one at load.
- With mapping "standard", use the standard layout: buttons[0] south, [1] east, [2] west, [3] north, [4]/[5] bumpers, [6]/[7] triggers, [8] back/select, [9] start, [12]-[15] D-pad, axes 0/1 left stick, 2/3 right stick. If mapping is not "standard", still treat buttons 0-3 as the face buttons and axes 0/1 as the left stick.
- Sticks: a round dead zone of about 0.2, rescaled so movement starts smoothly. Analog movement if the game can use it. The D-pad moves too.
- Feed the pad into the same input state the keyboard already uses, so the game logic doesn't change.
- Menu actions fire once on press, not every frame while held. When a button closes a menu, swallow it until it is released, so it doesn't also jump or shoot.
Button layout (by position, so it works on Xbox, PlayStation and Switch pads):
- South confirms and is the main action (jump). East goes back and cancels. West and north get the next most used actions.
- Start opens and closes pause. Back/select can restart or open a map, if the game has one.
- Every keyboard action gets a button. If there are more actions than buttons, use bumpers and triggers, or put rare actions in the pause menu.
Menus without a mouse:
- The D-pad and left stick move a visible focus highlight between items. Holding a direction repeats after about 0.4 s, then every 0.12 s. Up and down move between rows; left and right change the value of the focused row.
- When any screen opens, focus its first item (or the last one used on that screen). The focus highlight must be big and obvious, not a thin browser outline.
- South presses the focused item. East always goes back one screen. On the pause menu east resumes the game. Back must work on every screen.
- Sliders: left and right change the value in steps. Checkboxes: south toggles. Dropdowns (<select>): a browser dropdown can't be opened with a pad, so let left and right cycle the options in place.
- Anything that only appears on mouse hover (tooltips, extra info) must also appear when the item has focus.
- Don't turn the stick into a fake mouse cursor for menus.
Text fields:
- If a screen asks the player to type (a name, a code), give the pad an on-screen keyboard: a grid of letters, numbers, space, delete and done, moved with the D-pad, south types, east deletes, start or "done" confirms. Keep a physical keyboard working in the same field.
Button prompts:
- Track the last device the player touched. If it was the pad, every hint in the game shows pad buttons; if it was a key or the mouse, show the keyboard hints again. Change "Press R", "ESC to pause", "WASD to move" and every other key hint.
- Pick the button names from gamepad.id: Xbox (or unknown) A B X Y; PlayStation (contains "054c", "DualSense" or "DualShock") Cross Circle Square Triangle; Nintendo (contains "057e") B A Y X for the same positions. Draw them as small round badges with HTML/CSS or inline SVG, coloured like the real buttons, not as plain text in brackets.
- While the pad is in use, hide the mouse cursor and ignore mouse hover. Moving the mouse brings it back.
Safety:
- If the pad disconnects during play, pause the game and show "Controller disconnected".
- When the page loses focus, release every held input, so nothing gets stuck.
- If the browser offers vibrationActuator, add a short light rumble on important moments (a pickup, a hit) and a setting to turn it off. Skip it if the API is missing.
Before you finish, check your own work as a player with only a controller: start from the title, open and change every setting, go back, play, pause, resume, restart, quit to the title, finish a round and type a name. No step may need the keyboard or the mouse. Then check that keyboard and mouse still work as before.
Then tell me what you mapped to which button, and anything you couldn't map. Read more
Summary
Gamejam (@ShipOnGamejam on X) wrote an article about real gamepad support in browser games. Moving the character is not enough. Each menu needs a clear highlight. One button always confirms and one button always goes back. Left and right change settings. A small on-screen keyboard lets players type a name.
At the end, the article gives one long prompt. The prompt makes the AI list every input and every screen first. Then it connects the browser Gamepad API to the input the game already uses. Gamejam tested the prompt once in Claude Code on a small three.js game. They say it worked for about an hour and they changed nothing by hand.
For Cambodia
Many young Cambodians make small browser games with AI. Cheap USB and Bluetooth controllers are easy to buy here. This prompt makes a game playable on a controller from start to end. You do not need to learn the Gamepad API yourself.
Notes
Note
X article by Gamejam (@ShipOnGamejam on X), 26 Nov 2026, 'How to add real gamepad support to your browser game (and a prompt that does it)', read via the X API on 2026-11-27. The prompt is quoted verbatim from the code block in the article. The test result (about one hour in Claude Code, no hand changes, checked with a simulated controller) is their claim. Gamejam is a site for games made with AI, and the article ends with a link to it. The hero clip is the animated demo from the article. Title, summary and why are in our words.
Source
Open the original source.
https://x.com/ShipOnGamejam/status/2125978256448864602 (opens in a new tab)
The first category on a case is its primary purpose. Any later category is a secondary tag.