Enumerations
Button
Mapping of the button indices on a Gamepad to the
corresponding name of the button on the controller.
The order is not the standard Web Gamepad API order — it follows the
order of buttons as reported by the Switch's HID service. Always use this
enum (or named members) to look up buttons in Gamepad.buttons[] rather
than hard-coding indices.
Example
import { Button } from '@nx.js/constants';
const pad = navigator.getGamepads()[0];
if (pad.buttons[Button.A].pressed) {
console.log('Button A is pressed');
}Enumeration Members
| Enumeration Member | Value | Description |
|---|---|---|
A | 1 | A button (right-side face button — right position). |
B | 0 | B button (right-side face button on Pro/Joy-Con grip — down position). |
Down | 13 | D-Pad Down. |
L | 4 | L shoulder button. |
Left | 14 | D-Pad Left. |
Minus | 8 | Minus (–) button. |
Plus | 9 | Plus (+) button. |
R | 5 | R shoulder button. |
Right | 15 | D-Pad Right. |
StickL | 10 | Click of the Left Stick. |
StickR | 11 | Click of the Right Stick. |
Up | 12 | D-Pad Up. |
X | 3 | X button (left-side face button — up position). |
Y | 2 | Y button (left-side face button — left position). |
ZL | 6 | ZL trigger. |
ZR | 7 | ZR trigger. |