このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

GamepadButton: pressed プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2017年3月⁩.

GamepadButton.pressedGamepadButton インターフェイスのプロパティで、現在ボタンが押されている (true) か、押されていない (false) かを示す論理値を返します。

js
let gp = navigator.getGamepads()[0]; // 最初のゲームパッドオブジェクトを取得

if (gp.buttons[0].pressed) {
  // 押されているボタンに反応
}

論理値です。

仕様書

Specification
Gamepad
# dom-gamepadbutton-pressed

ブラウザーの互換性

関連情報