๐ฎ Simple customizable event binding for the HTML Gamepad API.
$ npm install neogeek/gamepad.js
const gamepad = new Gamepad();
gamepad.start();
const gamepad = new Gamepad();
gamepad.on('pressed', 'button_1', ({ id, gamepadIndex, value }) => {
console.log(
`${id} was pressed by player ${
gamepadIndex + 1
} with a value of ${value}!`
);
});
gamepad.start();
const gamepad = new Gamepad();
gamepad.on('held', 'button_1', ({ id, gamepadIndex, value }) => {
console.log(
`${id} is being held by player ${
gamepadIndex + 1
} with a value of ${value}!`
);
});
gamepad.start();
const gamepad = new Gamepad();
gamepad.on('released', 'button_1', ({ id, gamepadIndex, value }) => {
console.log(
`${id} was released by player ${
gamepadIndex + 1
} with a value of ${value}!`
);
});
gamepad.start();
const gamepad = new Gamepad();
gamepad.on('axes', 0, ({ id, gamepadIndex, value }) => {
console.log(
`${id} was held by player ${gamepadIndex + 1} with a value of ${value}!`
);
});
gamepad.on('axes', 1, ({ id, gamepadIndex, value }) => {
console.log(
`${id} was held by player ${gamepadIndex + 1} with a value of ${value}!`
);
});
gamepad.start();
gamepad.off('pressed', 'button_1');
gamepad.off('held', 'button_1');
gamepad.off('released', 'button_1');
- All keypad support has been removed to reduce complexity in the package.
- Gamepad type
press
is nowpressed
to conform to the browser standard. - Gamepad type
hold
is nowheld
. - Gamepad type
release
is nowreleased
.
The Gamepad browser API is very fragmented. VERY. Because of this we need your help. If you have a gamepad that isn't listed below, please visit the Gamepad.js Recorder and follow the instructions to create a controller mapping file. Either submit that in an issue or a PR. Once the mapping has been confirmed by at least one other user, it can be merged into the repo and it will be avaible in the next deploy.
Controller | Browser | OS | Supported |
---|---|---|---|
PS4 Wired | Chrome | macOS | โ |
PS4 Wired | Chrome | Windows | โ |
PS4 Wired | Firefox | macOS | โ |
PS4 Wired | Firefox | Windows | โ |
PS4 Wired | Microsoft Edge | Windows | โ |
PS4 Wired | Opera | macOS | โ |
PS4 Wired | Opera | Windows | โ |
PS4 Wired | Safari | macOS | โ |
Switch Pro Wired | Chrome | macOS | โ |
Switch Pro Wired | Chrome | Windows | โ |
Switch Pro Wired | Firefox | macOS | โ |
Switch Pro Wired | Firefox | Windows | โ |
Switch Pro Wired | Opera | macOS | โ |
Switch Pro Wired | Opera | Windows | โ |
Switch Pro Wired | Safari | macOS | โ |
Xbox One Wired | Chrome | macOS | โ |
Xbox One Wired | Chrome | Windows | โ |
Xbox One Wired | Firefox | macOS | โ |
Xbox One Wired | Firefox | Windows | โ |
Xbox One Wired | Microsoft Edge | Windows | โ |
Xbox One Wired | Opera | macOS | โ |
Xbox One Wired | Opera | Windows | โ |
Xbox One Wired | Safari | macOS | โ |