mozilla

Revision 513511 of Window.gamepadconnected

  • Revision slug: Web/API/window.gamepadconnected
  • Revision title: Window.gamepadconnected
  • Revision id: 513511
  • Created:
  • Creator: chrisdavidmills
  • Is current revision? No
  • Comment

Revision Content

{{ APIRef("window") }}

The Window.gamepadconnected event is fired when a gamepad is connected to the device.

Syntax

 attribute EventHandler gamepadconnected;

Example

window.addEventListener("gamepadconnected", function(e) {
  console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.",
  e.gamepad.index, e.gamepad.id,
  e.gamepad.buttons.length, e.gamepad.axes.length);
});

Specifications

{{page("/en-US/docs/Gamepad","Specifications")}}

Browser compatibility

{{page("/en-US/docs/Gamepad","Browser_compatibility")}}

See also

Using the Gamepad API

Revision Source

<p>{{ APIRef("window") }}</p>
<div class="summary">
 <p>The <strong><code>Window.gamepadconnected </code></strong>event is fired when a gamepad is connected to the device.</p>
</div>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">
<span class="idlInterface" id="idl-def-IDBOpenDBRequest"><span class="idlAttribute"> attribute <span class="idlAttrType">EventHandler</span> <span class="idlAttrName">gamepadconnected</span>;</span></span></pre>
<h2 id="Example">Example</h2>
<pre class="brush: js">
window.addEventListener("gamepadconnected", function(e) {
  console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.",
  e.gamepad.index, e.gamepad.id,
  e.gamepad.buttons.length, e.gamepad.axes.length);
});</pre>
<h2 id="Specifications">Specifications</h2>
<p>{{page("/en-US/docs/Gamepad","Specifications")}}</p>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{page("/en-US/docs/Gamepad","Browser_compatibility")}}</p>
<h2 id="See_also">See also</h2>
<p><a href="/en-US/docs/Web/Guide/API/Gamepad">Using the Gamepad API</a></p>
Revert to this revision