This article is in need of a technical review.
This article is in need of an editorial review.
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.
Using the Gamepad API
You can find a guide to using this API at Using the Gamepad API.
The Gamepad API consists of the following Interfaces:
- Defines an individual Gamepad or other controller, allowing access to information such as button presses, axis positions, and id.
- Defines the state of an individual button on a gamepad device.
- An interface that contains references to any connected gamepads, which is what the gamepad events (see below) are fired in response to.
The Gamepad API also defines some events and a specialist function:
Specialist events on the
Windowobject that allows us to react when a gamepad is connected or disconnected:
An extension to the
Navigatorobject that returns an array of
Gamepadobjects, one for each connected gamepad.
|Feature||Chrome||Firefox (Gecko)||Internet Explorer||Opera||Safari (WebKit)|
|General support||21.0 webkit||24.0 (24.0) moz
|Not supported||Not supported||Not supported|
|Feature||Android||Firefox Mobile (Gecko)||IE Phone||Opera Mobile||Safari Mobile|
|General support||Not supported||Not supported||Not supported||Not supported||Not supported|
Note: support for the Gamepad API differs a bit across browsers, as the spec is nascent and has undergone recent changes. For more cross browser information, read The Gamepad API by Ted Mielczarek and Robert Nyman.
- Editor's Draft at the W3C
- The Gamepad API by Ted Mielczarek and Robert Nyman
- Simple API demo page - https://bug604039.bugzilla.mozilla.org/attachment.cgi?id=549214
- Another API demo page - https://bug604039.bugzilla.mozilla.org/attachment.cgi?id=550638
- Example of using MozGamepad* listeners - https://gist.github.com/58b0f9ed647f72da9173