diff --git a/src/common/emu.ts b/src/common/emu.ts index 3ec11ac9..94b1b733 100644 --- a/src/common/emu.ts +++ b/src/common/emu.ts @@ -545,39 +545,55 @@ const DEFAULT_CONTROLLER_KEYS : KeyDef[] = [ export class ControllerPoller { active = false; handler; - state = new Int8Array(32); - lastState = new Int8Array(32); + state : Int32Array[]; + lastState : Int32Array[]; AXIS0 = 24; // first joystick axis index constructor(handler:(key,code,flags) => void) { this.handler = handler; window.addEventListener("gamepadconnected", (event) => { console.log("Gamepad connected:", event); - this.active = typeof navigator.getGamepads === 'function'; + this.reset(); }); window.addEventListener("gamepaddisconnected", (event) => { console.log("Gamepad disconnected:", event); + this.reset(); }); } + reset() { + this.active = typeof navigator.getGamepads === 'function'; + if (this.active) { + let numGamepads = navigator.getGamepads().length; + this.state = new Array(numGamepads); + this.lastState = new Array(numGamepads); + for (var i=0; i