Skip to content

Controller Events

jackcarey edited this page Jul 16, 2022 · 1 revision
Event Fires when…
gc.controller.found …a controller is connected or turned on.
gc.controller.lost …a controller is no longer visible to the browser.

gc.controller.found

The found event fires after a gamepad is connected and has been initialized. Depending on your browser this may happen as soon as you plug in or connect your gamepad, or you may have to press a button on the gamepad to "wake" it before it becomes visible.

This event passes the following to the detail property of the Event object:

Example

window.addEventListener('gc.controller.found', function(event) {
    console.log(event.detail);
}, false);

>> Object {
>>     controller: Controller, // a reference to this instance of Controller
>>     index: 0,
>>     time: 427075200,
>>     id: "Wireless Controller (STANDARD GAMEPAD Vendor: 054c Product: 05c4)"
>> }

gc.controller.lost

When the lost event fires it either means the gamepad has been physically or otherwise disconnected, or it has lost power.

This event passes the following to the detail property of the Event object:

  • id: The controller id.
  • timestamp: When the gamepad was disconnected, in Unix time.

Example

window.addEventListener('gc.controller.lost', function(event {
    console.log(event.detail);
}, false);

>> Object {
>>     index: 0,
>>     time: 498441600
>> }
Clone this wiki locally