LoginSignup
12
12

More than 5 years have passed since last update.

ChromeでGamepad API を叩く

Posted at

今更かもしれないけどChromeでデバッグ中にnavigator.getGamepads() 生えてるの気づいて調べた。

リファレンス見るのも面倒なので簡単にスニペットで動作確認。ゲームパッド指してこれを叩く。

// ボタンを抑えながら
> navigator.getGamepads()[0].buttons.map(function(b){return b.pressed})
[true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false]

// キーを押しながら
> navigator.getGamepads()[0].axes
[-0.9249231815338135, -0.380154013633728, 0, 0]

最初に気づかなかったけど、ポーリングしないとダメ。getGamepads()した時点のステータスが帰ってくる

あとはこれをみて察してくれ

Gamepad {buttons: Array[17], axes: Array[4], mapping: "standard", timestamp: 10712509240, connected: true…}axes: Array[4]0: 01: 02: 03: 0length: 4__proto__: Array[0]buttons: Array[17]connected: trueid: "Xbox 360 Controller (STANDARD GAMEPAD Vendor: 028e Product: 045e)"index: 0mapping: "standard"timestamp: 10712509240__proto__: Gamepad

Macに箱コン繋いでChromeのGamepad API 叩いてるの、業界オールスター感ある

参考
- Using the Gamepad API - Web developer guide | MDN

12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12