Gamepad API
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.
* Some parts of this feature may have varying levels of support.
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
TheGamepad API is a way for developers to access and respond to signals from gamepads and other game controllers in a simple, consistent way. It contains three interfaces, two events and one specialist function, to respond to gamepads being connected and disconnected, and to access other information about the gamepads themselves, and what buttons and other controls are currently being pressed.
In this article
Interfaces
GamepadRepresents a gamepad/controller connected to the computer.
GamepadButtonRepresents a button on one of the connected controllers.
GamepadEventThe event object representing events fired that are related to gamepads.
Experimental Gamepad extensions
GamepadHapticActuatorRepresents hardware in the controller designed to provide haptic feedback to the user (if available), most commonly vibration hardware.
GamepadPoseRepresents the pose of a controller (e.g., position and orientation in 3D space) in the case of aWebVR controller. This isnot used by the newerWebXR standard.
Extensions to other interfaces
Navigator
Navigator.getGamepads()An extension to the
Navigatorobject that returns an array ofGamepadobjects, one for each connected gamepad.
Window events
gamepadconnectedAn event that will fire when a gamepad is connected.
gamepaddisconnectedAn event that will fire when a gamepad is disconnected.
Tutorials and guides
Specifications
| Specification |
|---|
| Gamepad> # gamepad-interface> |
| Gamepad Extensions> # partial-gamepad-interface> |
Browser compatibility
See also
- The Gamepad API by Ted Mielczarek and Robert Nyman
- Simple API demo page (source)