-
-
Notifications
You must be signed in to change notification settings - Fork 17
The gamepad object
The connected gamepads will be stored in a list of gamepad objects. This gamepad object is not the default one returned by the browser but an interface to interact with it and simplify its usability.
| Name | Type | Description |
|---|---|---|
id |
String | ID of the controller. |
axes |
Integer | Number of axes/joysticks available on the gamepad. Notice that in some cases, what may seem like directional buttons are in reality a joystick. |
axeThreshold |
Number | Indicates the axe/joystick sensitivity threshold (when should the directional event be triggered). Values must be numeric and range between 0.0 and 1.0 (included). |
buttons |
Integer | Number of buttons available on the gamepad. |
mapping |
String |
Indicates if the gamepad matches the standard gamepad layout specified in the W3C definition. Possible values "standard" or "". If the value is "", developers may want to prompt a remap option to the users, as the buttons may not match the default ones displayed below..
|
vibration |
Boolean | Indicates if the vibration is supported for the gamepad/browser combination. This is an experimental feature. |
| Name and Parameters | Description |
|---|---|
.on(EVENTNAME, CALLBACK) |
Associates a function (callback) to be executed when the specified event is triggered (see list of events below). Example of use: At most one action can be associated to each event at any given moment. |
.off(EVENTNAME) |
Deassociates the event handler, so no action is performed when the event is triggered. Example of use: |
.vibrate([INTENSITY], [DURATION]) |
Triggers the gamepad vibration (if available). It can be called with up to two parameters
Example of use: |
.set(PROPERTY, VALUE) |
Sets the value of a property. At the moment, only the axeThreshold property can be used with this method.Example of use: |
This is a list of the events that can be associated to the gamepad object. They are the name of the button or directional joystick that will trigger the event when pressed/moved.
Not all events will be available in all the gamepads. E.g. if a gamepad only has 10 buttons, the events for button 11-16 will never be triggered. Also, aliases will work in "standard" gamepads (see properties above), but may not work as expected on non-standard gamepads.
| Name | Description |
|---|---|
button0 |
Triggered when button 0 is pressed. |
button1 |
Triggered when button 1 is pressed. |
button2 |
Triggered when button 2 is pressed. |
button3 |
Triggered when button 3 is pressed. |
button4 |
Triggered when button 4 is pressed. |
button5 |
Triggered when button 5 is pressed. |
button6 |
Triggered when button 6 is pressed. |
button7 |
Triggered when button 7 is pressed. |
button8 |
Triggered when button 8 is pressed. |
button9 |
Triggered when button 9 is pressed. |
button10 |
Triggered when button 10 is pressed. |
button11 |
Triggered when button 11 is pressed. |
button12 |
Triggered when button 12 is pressed. |
button13 |
Triggered when button 13 is pressed. |
button14 |
Triggered when button 14 is pressed. |
button15 |
Triggered when button 15 is pressed. |
button16 |
Triggered when button 16 is pressed. |
up0 |
Triggered when the first axe/joystick is moved up. |
down0 |
Triggered when the first axe/joystick is moved down. |
right0 |
Triggered when the first axe/joystick is moved right. |
left0 |
Triggered when the first axe/joystick is moved left. |
up1 |
Triggered when the second axe/joystick is moved up. |
down1 |
Triggered when the second axe/joystick is moved down. |
right1 |
Triggered when the second axe/joystick is moved right. |
left1 |
Triggered when the second axe/joystick is moved left. |
start |
Triggered when Start button is pressed. This is an alias for event button9. |
select |
Triggered when Select button is pressed. This is an alias for event button8. |
power |
Triggered when Power button is pressed (e.g. the Xbox logo in an Xbox controller). This is an alias for event button16. |
l1 |
Triggered when the left back button 1 is pressed. This is an alias for event button4. |
l2 |
Triggered when left back button 2 is pressed. This is an alias for event button6. |
r1 |
Triggered when right back button 1 is pressed. This is an alias for event button5. |
r2 |
Triggered when right back button 2 is pressed. This is an alias for event button7. |
up |
Triggered when the main/first axe/joystick is moved up. This is an alias for event up0. |
down |
Triggered when the main/first axe/joystick is moved down. This is an alias for event down0. |
right |
Triggered when the main/first axe/joystick is moved right. This is an alias for event right0. |
left |
Triggered when the main/first axe/joystick is moved left. This is an alias for event left0. |
These names are not arbitrary. They match the buttons and axes described in the W3C Gamepad API specicification: