Every controller, one API
Xbox, PlayStation, Switch Pro and generic gamepads read the same way. Buttons are named by position:
south is A on Xbox, Cross on PlayStation and B on Nintendo. Up to four players.
@gamepadly/sdk is an open-source JavaScript library that adds Xbox, PlayStation and Switch controller support to web games, with haptics and DualSense adaptive triggers. Give your coding agent one prompt, or add it yourself in about ten lines.
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.Works with any agent that can read a URL, such as Claude Code, Cursor, Codex or GitHub Copilot.
llms.txt is one page written for agents: which API to use in which situation,
copy-ready recipes, the mistakes to avoid, and a test template. More prompts.
The bridge presses the keys your game already listens for. The game’s code does not change.
import { createGamepadly } from '@gamepadly/sdk';import { createKeyMouseBridge } from '@gamepadly/sdk/bridge';
const hub = createGamepadly();const bridge = createKeyMouseBridge({ player: hub, profile: 'platformer' });bridge.start(); // D-pad and left stick → arrow keys, A / Cross → Space, ...
// Then make the game's own events felt:bridge.triggerHaptic('heavy_impact', { pan: -0.5 });Bind each action to controller, keyboard and mouse at once.
import { createGamepadly } from '@gamepadly/sdk';
const hub = createGamepadly();const p1 = hub.player(0);const actions = p1.createActions({ actions: { jump: ['south', 'Space'], fire: ['r2', 'MouseLeft'] }, axes: { moveX: { stick: 'lx', negativeKeys: ['KeyA'], positiveKeys: ['KeyD'] } },});
// In your game loop:actions.update(p1.input.getState(), performance.now());if (actions.justPressed('fire')) p1.haptics.playPreset('recoil');No build step: load the SDK from a CDN.
<script type="module"> import { createGamepadly, createKeyMouseBridge } from 'https://esm.sh/@gamepadly/sdk@0.9.0/browser';
const hub = createGamepadly(); createKeyMouseBridge({ player: hub, profile: 'arcade-4way' }).start();</script>Using a framework? See the recipes for Three.js, Phaser and React.
One call, p1.haptics.playPreset('recoil'), plays on whatever the controller has and returns
which output it used, so you can log it or assert on it in tests:
| Controller | What the player feels | Returns |
|---|---|---|
| DualSense with optional 4-channel audio (Windows, USB) | Voice-coil haptics, panned left and right | '4ch_vcm' |
| Switch Pro Controller, connected with one click (WebHID) | HD Rumble | 'hd_rumble' |
| Xbox Series controller in Chrome or Edge | Trigger motors and rumble | 'impulse_triggers' |
| DualSense and other controllers | Dual-motor rumble | 'dual_rumble' |
| No controller | Nothing; the game keeps running | 'none' |
Want to feel the difference? Plug a controller into the online controller tester, built on this SDK.
Every controller, one API
Xbox, PlayStation, Switch Pro and generic gamepads read the same way. Buttons are named by position:
south is A on Xbox, Cross on PlayStation and B on Nintendo. Up to four players.
Console features in the browser
One permission click in desktop Chrome or Edge unlocks DualSense adaptive triggers, gyro, touchpad and lightbar, and Switch Pro HD Rumble. Everything falls back on other controllers.
Tests without a controller
A mock controller you press in code. Tests run in Vitest or Jest in plain Node, so coding agents and CI can check controller support.
Small and safe
17.2 KB gzipped for the core, zero dependencies, MIT. Rumble and triggers reset when the page closes, and the SDK never writes controller firmware.
Controller input and rumble work in any modern browser that exposes the controller through the Gamepad API, with no prompt. Adaptive triggers, gyro, touchpad and HD Rumble need WebHID, which desktop Chrome and Edge support. Verified on real hardware so far: Windows with Chrome and Edge. Other platforms are implemented but not yet verified; the compatibility matrix tracks every combination.
Each example is one HTML file you can open, read and copy. Every one has a simulation mode, so you can try it without a controller.
Keyboard game → controller A keyboard-only shooter gets stick, trigger and haptics through the bridge.
Haptics playground Every haptic preset, trigger effect and lightbar color, and which output each controller uses.
Custom controller tester A tester built on the diagnostics module: circularity, drift and button bounce.An open-source (MIT) JavaScript and TypeScript library that adds controller support to web games: one API for Xbox, PlayStation, Switch Pro and other gamepads, haptics that use the best motor each controller has, DualSense adaptive triggers, and a bridge that makes an existing keyboard game playable on a controller without changing its code. It has no runtime dependencies.
Give the agent this prompt: “Read https://gamepadly.com/sdk/llms.txt, then add controller support to this game with @gamepadly/sdk.” The llms.txt file tells the agent which API to use, how to keep keyboard controls working, and how to write a test that runs without a controller.
No. Controller input and rumble use the browser’s Gamepad API with no prompt. DualSense adaptive triggers, gyro and touchpad and Switch Pro HD Rumble need one permission dialog (WebHID) in desktop Chrome or Edge. Only the optional DualSense speaker and 4-channel haptics on Windows can use a companion app, and games never require it.
Xbox controllers (including impulse triggers in Chrome and Edge), DualSense and DualSense Edge, the Switch Pro Controller, and any other controller the browser exposes through the Gamepad API. Verified on real hardware so far: Windows with Chrome and Edge. macOS, Linux, Firefox, Safari and mobile browsers are implemented but not yet verified. See the compatibility matrix.
Yes. The SDK does not depend on a framework: you read input once per frame from whatever loop you already have. In React, create the hub in useEffect and call dispose() in its cleanup.
createMockPlayerHandle() from @gamepadly/sdk/game is a fake controller whose buttons and sticks you set in code. Tests run in Vitest or Jest in plain Node. See the test example.
Yes. MIT licensed, no account, no API key, no server. It runs entirely in the player’s browser.