GamepadButton

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.

The GamepadButton interface defines an individual button of a gamepad or other controller, allowing access to the current state of different types of buttons available on the control device.

A GamepadButton object is returned by querying any value of the array returned by the buttons property of the Gamepad interface.

Instance properties

GamepadButton.pressed Read only

A boolean value indicating whether the button is currently pressed (true) or unpressed (false).

GamepadButton.touched Read only

A boolean value indicating whether the button is currently touched (true) or not touched (false).

GamepadButton.value Read only

A double value used to represent the current state of analog buttons, such as the triggers on many modern gamepads. The values are normalized to the range 0.0 —1.0, with 0.0 representing a button that is not pressed, and 1.0 representing a button that is fully pressed.

Example

The button values in the following example are stored as an array of GamepadButton objects. This simple example checks to see if the GamepadButton.value of a button is greater than 0, or if the GamepadButton.pressed property indicates the button has been pressed.

js
function gameLoop() {
  const gp = navigator.getGamepads()[0];

  if (gp.buttons[0].value > 0 || gp.buttons[0].pressed) {
    b--;
  } else if (gp.buttons[1].value > 0 || gp.buttons[1].pressed) {
    a++;
  } else if (gp.buttons[2].value > 0 || gp.buttons[2].pressed) {
    b++;
  } else if (gp.buttons[3].value > 0 || gp.buttons[3].pressed) {
    a--;
  }

  ball.style.left = `${a * 2}px`; // ball is a UI widget
  ball.style.top = `${b * 2}px`;

  requestAnimationFrame(gameLoop);
}

Specifications

Specification
Gamepad
# gamepadbutton-interface

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
GamepadButton
Chrome – Full support
Chrome 21 (Release date: 2012-07-31)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 29 (Release date: 2014-04-29)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 25 (Release date: 2013-02-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 32 (Release date: 2014-09-02)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
pressed
Chrome – Full support
Chrome 21 (Release date: 2012-07-31)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 29 (Release date: 2014-04-29)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 25 (Release date: 2013-02-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 32 (Release date: 2014-09-02)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Secure context required
Experimental
Chrome – No support
Chrome 86 (Release date: 2020-10-20)
disabled
disabled From version 86 users must explicitly set the #restrict-gamepad-access preference to Enabled. To change preferences in Chrome, visit chrome://flags.
Edge – No support
Edge 86 (Release date: 2020-10-09)
disabled
disabled From version 86 users must explicitly set the #restrict-gamepad-access preference to Enabled. To change preferences in Edge, visit about:flags.
Firefox – Full support
Firefox 91 (Release date: 2021-08-10)
footnote Full support
Opera – No support
Opera 72 (Release date: 2020-10-21)
disabled
disabled From version 72 users must explicitly set the #restrict-gamepad-access preference to Enabled. To change preferences in Opera, visit opera://flags.
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android 86 (Release date: 2020-10-20)
disabled
disabled From version 86 users must explicitly set the #restrict-gamepad-access preference to Enabled. To change preferences in Chrome Android, visit chrome://flags.
Firefox for Android – Full support
Firefox for Android 91 (Release date: 2021-08-10)
footnote Full support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
touched
Chrome – Full support
Chrome 73 (Release date: 2019-03-12)
footnote Full support
Edge – Full support
Edge 15 (Release date: 2017-04-05)
footnote Full support
Firefox – Full support
Firefox 55 (Release date: 2017-08-08)
footnote Full support
Opera – Full support
Opera 60 (Release date: 2019-04-09)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 73 (Release date: 2019-03-12)
footnote Full support
Firefox for Android – Full support
Firefox for Android 55 (Release date: 2017-08-08)
footnote Full support
Opera Android – Full support
Opera Android 52 (Release date: 2019-05-17)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 11 (Release date: 2019-12-05)
footnote Full support
WebView Android – Full support
WebView Android 73 (Release date: 2019-03-12)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
value
Chrome – Full support
Chrome 21 (Release date: 2012-07-31)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 29 (Release date: 2014-04-29)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 25 (Release date: 2013-02-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 32 (Release date: 2014-09-02)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.

See also

Using the Gamepad API