Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <h1>Gamepad detection</h1>
  <p>
  Please connect a gamepad on one of the USB port (we have not tried any wireless gamepad yet). And press a button. <b>Then look at the console</b>.</p>
  <p>With Google Chrome the game pad is detected when you plug it and first interact with it.</p>
  <p>With FireFox it's detected as soon as you plug it.</p>
</body>
</html>
 
window.addEventListener("gamepadconnected", function(e) {
   var gamepad = e.gamepad;
   var index = gamepad.index;
   var id = gamepad.id;
   var nbButtons = gamepad.buttons.length;
   var nbAxes = gamepad.axes.length;
   console.log("Gamepad No " + index +
               ", with id " + id + " is connected. It has " +
               nbButtons + " buttons and " +
               nbAxes + " axes");
});
window.addEventListener("gamepaddisconnected", function(e) {
   var gamepad = e.gamepad;
   var index = gamepad.index;
   console.log("Gamepad No " + index + " has been disconnected");
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
MichelBuffapro
0viewers