How do I access gamepad events through JavaScript?

I’ve created a small game in which ten players compete locally. I’ve done this by using JoyToKey to remap several buttons from a number of gamepads to 40 different keystrokes. This works, but has two major drawbacks: 1) Anyone else who would like to play this game will have to set up their own keystroke emulator; 2) I can only use as many buttons across all controllers as I can map onto one keyboard (max of about 5 per controller).

I’ve been looking at the Gamepad extension in order to understand how one uses JavaScript and events to access the states of gamepad button presses, etc. But don’t see where the interface between the extension and the OS is happening in order to get at the button presses.

What is the Gamepad extention using to access controller button states, and what resources do I need to be looking at in order to understand it and create something like it myself?

Why not use behaviors that reduce all your fatigue?

You will find in the extension a structure that defines a number for each button; this number is the gamepad button from the gamepad API from the browser. I imagine you should edit this table according to the mapping on your device.

And just a quick reminder: Java is not JavaScript !
GDevelop uses JavaScript.
here is no Java in GDevelop.
I am editing your message to set the truth.

Thanks for setting me straight on Java vs JavaScript.

I’m starting to understand how this works:

  • The Gamepads Extension
  • …Uses the Gamepads API
  • …Which is implemented in most of the major Browsers
  • …Which tap into something even deeper in order to access gamepads.

Is it correct that the limit of four controllers is only imposed by the browser? I cannot find a place in either the Gamepad API documentation or in the GDevelop Gamepad Extension which limits the number of controllers to four.

As far as I remember, this limit is browser-related. I had found too that it wasn’t possible to have more, sadly.