Gamepad Module
Contents
Gamepads, Axis, and Button IDs
Both gamepads and buttons start with an index of 1. That is, the first detected gamepad had an ID of 1, and the first button on that gamepad has a button ID of 1.
Up to 16 gamepads are supported. Up to 32 buttons and 6 axis per gamepad are supported. Any gamepads you wish to read input from should be plugged in before starting a script in which you intend to use it for.
Global variables
To make working with the POV hat (aka D-pad) a bit easier, a few variables have been added to global scope:
JOY_POVBACKWARD | The "Down" button; A value of 180 |
JOY_POVFORWARD | The "Up" button; A value of 0 |
JOY_POVCENTERED | No direction; A value of 655 |
JOY_POVLEFT | The "Left" button; A value of 270 |
JOY_POVRIGHT | The "Right" button; A value of 90 |
pressed
boolean gamepad.pressed(number gamepadId, number button)
If the given gamepad has had its button pressed since last polling, returns true. Else, false.
released
boolean gamepad.released(number gamepadId, number button)
If the given gamepad has had its button released since last polling, returns true. Else, false.
isDown
boolean gamepad.isDown(number gamepadId, number button)
If the given gamepad currently has a given button held down (as of last polling), returns true. Else, returns false.
getPOV
number gamepad.getPOV(number gamepadId)
Returns the angle of the POV hat (D-pad). If centered, returns JOY_POVCENTERED. This angle is in degrees with "up" being 0° and rotating in a clockwise fashion.
getAxis
number gamepad.getAxis(number gamepadId, number axisId)
Returns the axis value for a given gamepad. The value will be between 0 (minimum) and 100(maximum). If centered, the value will be ~50.
This will not always be exact! Due to calibration, floating-point inaccuracies, and physical defects, you may receive a value that is a fraction off the intended value. I.e. ~49-51 while centered.
getCount
number gamepad.getCount()
Returns the number of connected gamepads.