🎮 Simple customizable event binding for the HTML Gamepad API.
MIT License
🎮 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');
press
is now pressed
to conform to the browser standard.hold
is now held
.release
is now released
.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 | ✅ |