{{SeeCompatTable}}
The Gamepad 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.
Reference
The following interfaces are defined in the Gamepad API
- {{domxref("Gamepad")}}
- {{domxref("GamepadButton")}}
- {{domxref("GamepadEvent")}}
The Gamepad API also defines some events and a specialist function:
-
Gamepad
Window
events - Specialist events on the {{domxref("Window")}} object that allows us to react when a gamepad is connected or disconnected: {{event('gamepadconnected')}} and {{event('gamepaddisconnected')}}. Event handlers can be easily set using {{domxref("Window.ongamepadconnected")}} and {{domxref("Window.ongamepaddisconnected")}}.
- {{domxref("Navigator.getGamepads()")}}
- An extension to the {{domxref("Navigator")}} object that returns an array of {{domxref("Gamepad")}} objects, one for each connected gamepad.
Tutorials and guides
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('Gamepad', '', 'The Gamepad API specification')}} | {{Spec2('Gamepad')}} |
Browser compatibility
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
General support |
21.0 {{ property_prefix("webkit") }} |
{{ CompatGeckoDesktop("29.0") }} | {{ CompatNo() }} |
15.0 {{ property_prefix("webkit") }} |
{{ CompatNo() }} |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
General support | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} |
See also
- Editor's Draft at the W3C
- The Gamepad API by Ted Mielczarek and Robert Nyman
- Simple API demo page (source)