jsgamepad
Version:
W3C Gamepad API Simplified & Implementation fixes
56 lines (38 loc) • 1.51 kB
Markdown
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![License][license-image]][license-url]
**W3C Gamepad API Simplified & Implementation fixes**
[](https://ardean.github.io/jsGamepad/)
[](https://w3c.github.io/gamepad/)
This lib fixes a bug in Chrome, where the `connected` event will be emitted instead of the `disconnected` event.
I suggest you to use [jspm](http://jspm.io/) as your package manager.
```js
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();
```
Please checkout the [index-dist.html](https://ardean.github.io/jsGamepad/index-dist.html) file for direct usage in a browser.
- API
[](LICENSE)
[]: https://img.shields.io/npm/v/jsgamepad.svg
[]: https://npmjs.org/package/jsgamepad
[]: https://img.shields.io/npm/dm/jsgamepad.svg
[]: https://npmjs.org/package/jsgamepad
[]: https://img.shields.io/npm/l/jsgamepad.svg
[]: LICENSE