Skip to content

Why not the raw Gamepad API?

The browser’s Gamepad API reads the buttons and sticks of any controller and plays simple rumble. For a game that reads a few buttons on one controller, that is enough, and you may not need this SDK. @gamepadly/sdk covers what comes next: the code most games end up writing on top of the Gamepad API, and the controller features the Gamepad API cannot reach at all.

Jump with the bottom face button, and rumble when the player lands. With the Gamepad API:

let wasDown = false;
function update() {
// getGamepads() returns a fixed-length array with null in empty slots. It stays empty
// until the player presses a button.
const pad = navigator.getGamepads().find((p) => p !== null);
if (!pad) return;
// Index 0 is the bottom face button only when pad.mapping is 'standard'.
const down = pad.buttons[0]?.pressed ?? false;
if (down && !wasDown) jump();
wasDown = down;
}
function onLand() {
const pad = navigator.getGamepads().find((p) => p !== null);
// vibrationActuator is missing for some browsers and controllers.
void pad?.vibrationActuator?.playEffect('dual-rumble', { duration: 150, strongMagnitude: 0.8, weakMagnitude: 0.4 });
}

With the SDK:

import { createGamepadly } from '@gamepadly/sdk';
const hub = createGamepadly();
const p1 = hub.player(0);
const actions = p1.createActions({ actions: { jump: ['south', 'Space'] } }); // the keyboard keeps working
function update(now: number) {
actions.update(p1.input.getState(), now);
if (actions.justPressed('jump')) jump();
}
function onLand() {
p1.haptics.playPreset('heavy_impact'); // on the best motor this controller has
}

Both are short. The difference is what each one leaves to you as the game grows.

Need Gamepad API @gamepadly/sdk
Press and release Compare each frame with the previous one justPressed(), justReleased(), hold time
Keyboard and controller together Two input paths One action binds buttons and keys
Stick deadzone Your own 0.08 by default, per axis
Button names Indexes, valid only when mapping is 'standard' Position names (south, east, …) and rules for non-standard layouts
Prompts for the player’s controller Parse pad.id, whose format differs between Chrome and Firefox getButtonLabel('south', brand) gives A, Cross or B
Several players, hotplug Array slots with gaps, reused on reconnect hub.player(n) handles that keep working across reconnects
Haptics 'dual-rumble', plus 'trigger-rumble' for Xbox in Chrome and Edge Presets with left-right pan, played on the best motor; each call returns which one
An existing keyboard game Rewrite its input The bridge presses its keys
Tests without a controller Stub navigator.getGamepads() createMockPlayerHandle()
Teardown Stop rumble yourself dispose(), and an automatic reset when the page closes

None of this is hard on its own. Together it is the input layer of a game, and the SDK is that layer, tested and typed.

These features are not part of the Gamepad API:

  • DualSense adaptive triggers, lightbar, gyroscope and touchpad
  • Switch Pro HD Rumble and gyroscope
  • the DualSense speaker and its two voice-coil haptic actuators

The first two groups go through WebHID, where the page talks to the controller in its own binary protocol. For a DualSense over Bluetooth that means building output reports with a CRC32 checksum, and for a Switch Pro, encoding HD Rumble frequencies and reading the stick calibration from the controller’s memory. The SDK implements these reports. It only reads controller memory and never writes firmware or settings. WebHID needs one permission click in desktop Chrome or Edge, and every feature falls back when it is not available. The third group needs Windows, a USB cable and the optional audio path. Capability tiers lists what needs what.

  • One controller, a few buttons, rumble at most. The Gamepad API is enough, and it adds nothing to your bundle. The SDK core adds 17.2 KB gzipped.
  • Your engine already reads controllers. Engines read controllers through the same Gamepad API. Phaser’s gamepad plugin, for example, exposes the browser’s vibrationActuator as is. Keep the engine’s input and use the SDK only for haptics, adaptive triggers and button labels. The Phaser recipe shows both ways.
  • The game is exported from Unity or Godot. Use the engine’s own input system. The SDK is a JavaScript library for code that runs in the page.
  • You only target DualSense and want everything it has, including player LEDs and Node.js support. A DualSense-only library such as dualsense-ts covers more of that one controller.

Each of these does one part well. Details are from their npm pages and READMEs as of December 2026.

Library What it covers License
dualsense-ts DualSense and DualSense Access, in the browser through WebHID and in Node.js through node-hid: inputs, rumble, trigger effects, lightbar and player LEDs, touchpad, motion LGPL-3.0
jsDualsense DualSense and DualSense Edge through WebHID: inputs, LEDs, rumble, adaptive triggers, audio MIT
joy-con-webhid Joy-Con through WebHID: buttons, sticks, LEDs, gyroscope, accelerometer, rumble Apache-2.0
Joymap A Gamepad API wrapper: button and stick mapping and remapping, rumble through playEffect MIT
gamecontroller.js Gamepad API events for each button and stick. Last release in 2020 MIT

@gamepadly/sdk is MIT licensed, has no runtime dependencies and runs only in the browser. It reads Xbox, PlayStation, Switch Pro and other controllers through one API, and adds WebHID features for DualSense and Switch Pro. It does not support Joy-Con over WebHID, and DualShock 4 works through the Gamepad API only. So far it is verified on hardware with Windows and Chrome or Edge; see Compatibility.