gamepad-event-dispatcher

0.0.2 • Public • Published

gamepad-event-dispatcher

gamepad-event-dispatcher is a lightweight event-based wrapper for the browser gamepad API.

Installation

Install the module using npm:

npm install gamepad-event-dispatcher

Usage

Import the module:

import { gamepadEvents } from '/node_modules/gamepad-event-dispatcher/src/index.js';

Attach listeners as required:

gamepadEvents.addEventListener("a", e => console.log("You pressed the A button"));
gamepadEvents.addEventListener("left", e => console.log("You pressed the Left D-PAD button"));

Get 'velocity' values from triggers and joystick directions with the 'detail.value' property of the event:

gamepadEvents.addEventListener("righttrigger", e => console.log(e.detail.value));

Full list of default input names:

"a", "b", "x", "y",
"leftbumper", "rightbumper", "lefttrigger", "righttrigger",
"view", "menu",
"leftjoypressed", "rightjoypressed",
"up", "down", "left", "right",
"leftjoyleft", "leftjoydown", "leftjoyright", "leftjoyup",
"rightjoyleft", "rightjoydown", "rightjoyright", "rightjoyup"

Advanced Usage

Update input names by importing the config module and using 'setGamepadInput':

import { gamepadEventsConfig } from '/node_modules/gamepad-event-dispatcher/src/index.js';

gamepadEventsConfig.setGamepadInput(3, "triangle");

This will would allow the following code to be used:

gamepadEvents.addEventListener("triangle", e => console.log("You pressed the triangle button"));

Package Sidebar

Install

npm i gamepad-event-dispatcher

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

10.5 kB

Total Files

6

Last publish

Collaborators

  • rex-tr909