Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Gamepad

Gamepad

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.

TheGamepad interface of theGamepad API defines an individual gamepad or other controller, allowing access to information such as button presses, axis positions, and id.

A Gamepad object can be returned in one of two ways: via thegamepad property of thegamepadconnected andgamepaddisconnected events, or by grabbing any position in the array returned by theNavigator.getGamepads() method.

Note:The support of gamepad features varies across different combinations of platforms and controllers. Even if the controller supports a certain feature (for example, haptic feedback), the platform may not support it for that controller.

Instance properties

Gamepad.axesRead only

An array representing the controls with axes present on the device (e.g., analog thumb sticks).

Gamepad.buttonsRead only

An array ofgamepadButton objects representing the buttons present on the device.

Gamepad.connectedRead only

A boolean indicating whether the gamepad is still connected to the system.

Gamepad.displayIdRead onlyDeprecatedNon-standard

Returns theVRDisplay.displayId of an associatedVRDisplay (if relevant) — theVRDisplay that the gamepad is controlling the displayed scene of.

Gamepad.handRead onlyExperimental

An enum defining what hand the controller is being held in, or is most likely to be held in.

Gamepad.hapticActuatorsRead onlyExperimental

An array containingGamepadHapticActuator objects, each of which represents haptic feedback hardware available on the controller.

Gamepad.vibrationActuatorRead only

AGamepadHapticActuator object, which represents haptic feedback hardware available on the controller.

Gamepad.idRead only

A string containing identifying information about the controller.

Gamepad.indexRead only

An integer that is auto-incremented to be unique for each device currently connected to the system.

Gamepad.mappingRead only

A string indicating whether the browser has remapped the controls on the device to a known layout.

Gamepad.poseRead onlyExperimental

AGamepadPose object representing the pose information associated with a WebVR controller (e.g., its position and orientation in 3D space).

Gamepad.timestampRead only

ADOMHighResTimeStamp representing the last time the data for this gamepad was updated.

Example

js
window.addEventListener("gamepadconnected", (e) => {  console.log(    "Gamepad connected at index %d: %s. %d buttons, %d axes.",    e.gamepad.index,    e.gamepad.id,    e.gamepad.buttons.length,    e.gamepad.axes.length,  );});

Specifications

Specification
Gamepad
# gamepad-interface
Gamepad Extensions
# partial-gamepad-interface

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp