This open-source library is a wrapper for the JavaScript Gamepad API. It was made in response to issues I faced trying to use the API to build prototypes of controller-compatible interfaces.

An overhead shot of two hands holding a wired Playstation 4 controller, over a wooden table.

Most user-interactions on the web (e.g. mouse clicks or touches) are event-driven — you register listeners that call functions in response to an event firing — but the Gamepad API is designed such that you must poll a gamepad object whenever you want to know its current state. This paradigm works well in game development but may be unfamiliar to web developers.

With Controller.js, I sought to make programming for gamepads feel familiar to programming for mouse or touch inputs. On top of this I added other convenient functionality, including button re-mappings for different gamepads, analog stick sensitivity settings, and mapping of analog stick presses to D-pad events.