Gamepad

The Gamepad interface of the Gamepad API defines an individual gamepad. A Gamepad object can be returned via the gamepad property of the gamepadconnected and gamepaddisconnected events, or by grabbing any position in the array returned by the navigator.getGamepads() method.


Properties:
.axes
An array representing the controls with axes present on the device (e.g. analog thumbsticks).

.buttons
An array of gamepadButton objects representing the buttons present on the device.

.connected
A Boolean indicating whether the gamepad is still connected to the system.

.displayId
Returns the VRDisplay.displayId of an associated VRDisplay (if relevant) — the VRDisplay that the gamepad is controlling the displayed scene of.

.id
A DOMString containing identifying information about the controller.

.index
An integer that is auto-incremented to be unique for each device currently connected to the system.

.mapping
A string indicating whether the browser has remapped the controls on the device to a known layout.

.timestamp
A DOMHighResTimeStamp representing the last time the data for this gamepad was updated.

.hand
An enum defining what hand the controller is being held in, or is most likely to be held in.

.hapticActuators
An array containing GamepadHapticActuator objects, each of which represents haptic feedback hardware available on the controller.

.pose
A GamepadPose object representing the pose information associated with a WebVR controller (e.g. its position and orientation in 3D space).

window.addEventListener("gamepadconnected", e => {
  console.log(`Gamepad connected at index %d: %s. %d buttons, %d axes.`,
     e.gamepad.index, 
     e.gamepad.id,
     e.gamepad.buttons.length, 
     e.gamepad.axes.length);
});