Gamepad API Test

🎮/🕹 Press button on gamepad / joystick to start output

The Gamepad API

The Gamepad API works differently on different browsers and operating systems. Also different brands of gamepads, joysticks, throttles etc. register a different set of buttons and axes.

If a gamepad registers with standard mapping, the browser does some remapping of buttons and axes to fit a virtual standard gamepad.

Special buttons and axes

Analog triggers
On standard mapping this button has a pressed state and an analog value with values 0..+1. On other browsers this may not show up as a button but as an axis instead, with values -1..+1.
Throttles
Theses axes always transmit a value with values -1..+1.
Convert this axis to 0..+1: const throttle = (axis + 1) / 2;
Coolie hats
This control may look like four buttons or two axis - but in fact it has just a single axis with 8 (+1) possible values. The value of 0° position is -1, adding 0.5715 for every 90° position. The maximum position is 315° which outputs +1. In centered hat state the axis reads an out of bounds positive value.
Convert this axis to an 8-way-axis: const coolie = (axis > 1) ? undefined : Math.round((axis + 1) * 7/2);
Convert this axis to an 4-way-axis: const coolie = (axis > 1) ? undefined : Math.round((axis + 1) * 7/4) % 4;