Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Navigator
  4. getGamepads()

Navigator: getGamepads() method

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.

TheNavigator.getGamepads() method returns an array ofGamepad objects, one for each gamepad connected to the device.

Elements in the array may benull if a gamepad disconnects during asession, so that the remaining gamepads retain the same index.

Syntax

js
getGamepads()

Parameters

None.

Return value

AnArray ofGamepad objects, eventually empty.

Exceptions

SecurityErrorDOMException

Use of this feature was blocked by aPermissions Policy.

Examples

js
window.addEventListener("gamepadconnected", (e) => {  const gp = navigator.getGamepads()[e.gamepad.index];  console.log(    `Gamepad connected at index ${gp.index}: ${gp.id} with ${gp.buttons.length} buttons, ${gp.axes.length} axes.`,  );});

Specifications

Specification
Gamepad
# dom-navigator-getgamepads

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp