getGamepads()
The getGamepads()
function provides access to connected game controllers in OSL applications. It returns an array of gamepad objects with normalized properties for easy access to controller inputs.
Return Value
Returns an array of gamepad objects, with each object containing the following properties:
id
: String identifying the gamepadindex
: Numeric index of the gamepadconnected
: Boolean indicating if the gamepad is connectedtimestamp
: The last time the gamepad state was updatedmapping
: String indicating the mapping type (e.g., "standard")axes
: Array of objects representing analog sticks, each with:x
: X-axis value (range: -1.0 to 1.0)y
: Y-axis value (range: -1.0 to 1.0, inverted for natural directional control)
buttons
: Array of button objects, each with:pressed
: Boolean indicating if the button is pressedtouched
: Boolean indicating if the button is touchedvalue
: Numeric value of the button pressure (range: 0.0 to 1.0)
haptic
: Function to trigger vibration feedback on the controller (when supported)
Common Button Indexes
Example application
An app with support for gamepads is Arrow by Mist, source code found below:
Example: Checking a Specific Button Press
Example: Reading Analog Stick Values
Example: Using Haptic Feedback
Notes
If no gamepads are connected, the function returns an empty array.
Gamepad support varies by browser and device.
The haptic function may not work on all controllers or platforms.
Last updated
Was this helpful?