Konchai
Gamepad event listener library
Usage
import { gamepad } from "konchai";
const gp = gamepad();
// Listen to any button
const unlisten1 = gp.change((name, value) => {
console.log(name, value);
if (gp.state.buttons.right && gp.state.buttons["face-top"]) {
console.log("> + ^");
}
});
// Listen to certain button
const unlisten2 = gp.on("home", (value) =>
console.log(value ? "Home Pressed" : "Home Unpressed")
);
document.getElementById("stop-listen-to-gamepad-events-button").onclick =
() => {
unlisten1(), unlisten2();
};