Skip to content

Buttons and layouts

Face buttons carry different labels on every brand. The button Xbox prints A is Cross on PlayStation and B on Nintendo. Bind by position so the same code works everywhere:

Name Position Xbox PlayStation Nintendo
south bottom face button A Cross B
east right face button B Circle A
west left face button X Square Y
north top face button Y Triangle X
select left center button View Create Minus
start right center button Menu Options Plus
home logo button Guide Home Home

Shoulders and sticks use l1, r1, l2 / r2 (analog) or l2Btn / r2Btn (digital), l3, r3, and the D-pad uses up, down, left, right.

The aliases resolve to the SDK’s underlying names (south → cross, start → options, …), so older code that uses cross or options keeps working. resolveButtonName() performs the same lookup if you need it.

import { getButtonLabel } from '@gamepadly/sdk';
const brand = p1.getCapabilities().identity.brand;
hint.textContent = `Press ${getButtonLabel('south', brand)} to jump`; // "A", "Cross", or "B"

Generic and unknown controllers get the A / B / X / Y labels most PC pads print. Labels are plain text. Draw your own icons if you want glyphs. Re-render prompts in hub.onCapabilitiesChange, since the player can switch controllers mid-game.

Button positions are only reliable when the browser reports the W3C standard gamepad layout. Check p1.input.getState().mapping:

Value Meaning
'standard' Standard layout, indices are reliable
'nonstandard' The browser reported no standard mapping; buttons may be misnamed
'custom' One of your gamepadMappings rules remapped this controller
'hid' Read directly over WebHID, always correct
'none' No controller (keyboard / mouse or disconnected)

'nonstandard' is more common in Firefox and Safari and with some third-party pads. When you see it, you can:

  1. Show the player a hint that buttons may be mixed up.
  2. For DualSense or Switch Pro, offer hub.connectWebHID(), which reads the controller directly.
  3. Pass your own layout:
import { createGamepadly } from '@gamepadly/sdk';
const hub = createGamepadly({
gamepadMappings: [
{
match: (pad) => pad.mapping === '' && pad.id.includes('Vendor: 0079'),
buttons: { cross: 2, circle: 1, square: 3, triangle: 0 },
axes: { rx: 3, ry: { index: 4, invert: true } },
triggers: { l2: { axis: 2 }, r2: { button: 7 } },
},
],
});

The first rule whose match returns true is used. buttons maps SDK button names to raw button indices, axes maps sticks to raw axis indices, and triggers reads each analog trigger from a button value or an axis (signed -1..1 axes are rescaled to 0..1). The indices above are illustrative: log navigator.getGamepads() for your controller to find the real ones. The compatibility matrix tracks which combinations have been verified.