So I was trying to simulate a controller in JavaScript but couldn’t find a way to construct a new Gamepad() and could not figure out how to work this out from the docs could anybody help.
This is what my current code looks like:
function simulateControllerInput(key) {
const mapping = keyMappings[key];
if (mapping) {
const simulatedGamepad = new Gamepad(); // <-- This is where I want to construct the Gamepad
simulatedGamepad.axes = mapping.axes;
const buttonEvent = new GamepadEvent("gamepadbuttondown", {
bubbles: true,
cancelable: true,
gamepad: simulatedGamepad,
});
document.dispatchEvent(buttonEvent);
}
}
