jsgamepad

W3C Gamepad API Simplified & Implementation fixes

Usage no npm install needed!

<script type="module">
  import jsgamepad from 'https://cdn.skypack.dev/jsgamepad';
</script>

README

jsGamepad

NPM Version NPM Downloads License

W3C Gamepad API Simplified & Implementation fixes

Demo

Specification

Gamepad API, W3C

Fixes

This lib fixes a bug in Chrome, where the connected event will be emitted instead of the disconnected event.

Usage

I suggest you to use jspm as your package manager.

import gamepad from "jsgamepad";

gamepad.on("connected", (gamepad) => {
  console.log("connected " + gamepad.index);
}).on("disconnected", (gamepad) => {
  console.log("disconnected " + gamepad.index);
}).on("buttonPressed", ({ button, buttonIndex, gamepad }) => {
  console.log("pressed " + buttonIndex);
}).on("buttonReleased", ({ button, buttonIndex, gamepad }) => {
  console.log("released " + buttonIndex);
});

// start loop for buttons and axes detection
gamepad.watch();

Directly in a browser

Please checkout the index-dist.html file for direct usage in a browser.

TODO

  • API

License

MIT