Bindings for Alex Diener's cross-platform gamepad code
The library is tiny and included inside this addon so you don't need any special libraries installed on your system like SDL.
To install as a dependency simple type the following in your project's folder:
npm install gamepad
var gamepad = ;// Initialize the librarygamepad// List the state of all currently attached devicesfor var i = 0 l = gamepad; i < l; i++console;// Create a game loop and poll for events;// Scan for new gamepads as a slower rate;// Listen for move events on all gamepadsgamepad;// Listen for button up events on all gamepadsgamepad;// Listen for button down events on all gamepadsgamepad;
There are 5 event types
move. All pass the session id of the gamepad as the first argument.
attach event also passes current state as the second arg to attach.
up events also pass in the button id and timestamp after device session id.
move event passes axis, value, old value and timestamp after session id.
Initializes gamepad library and detects initial devices. Call this before any
other library function. If you want to receive attach events callbacks from
devices detected in
gamepad.init(), you must listen for
Tears down all data structures created by the gamepad library and releases any memory that was allocated. It is not necessary to call this function at application termination, but it's provided in case you want to free memory associated with gamepads at some earlier time.
Returns the number of currently attached gamepad devices.
Returns the specified gamepad's current state, or
undefined if deviceIndex is
out of bounds.
Polls for any devices that have been attached since the last call to
gamepad.init(). If any new devices are found, the
attach event will be emitted once per newly detected device.
Note that depending on implementation, you may receive button and axis event
callbacks for devices that have not yet been detected with
gamepad.detectDevices(). You can safely ignore these events, but be aware that
your callbacks might receive a device ID that hasn't been emitted as an
Reads pending input from all attached devices and emits the appropriate events, if any have been registered.