demo · v143

Handler Attributes

The page sets window.ongamepadconnected and window.ongamepaddisconnected. Plug in a gamepad — the log fires and the pad's state polls live.

capability probe

handler log

connected gamepads (polled)

no pads connected

the call

// v143: handler-attribute style
window.ongamepadconnected = (e) => {
  console.log("connected", e.gamepad.id, e.gamepad.index);
};
window.ongamepaddisconnected = (e) => {
  console.log("disconnected", e.gamepad.id);
};

see also