User Tools

Site Tools


Privacy Policy


Version 2.50 is out since Jan 1st 2022

Frequently Asked Questions


Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax



(Information and examples taken from the DroidScript documentation)


The GetJoystickState method gets the state of a button or axis of a HID Joystick or Gamepad (For example, an Xbox 360 controller connected to your device via an OTG cable).

app.GetJoystickState( joyNum, keyName );

GetJoystickState can get the state of multiple HID controllers currently connected to your device. Pass 0 to GetJoystickState for the first controller, 1 for the second, etc.

The state of a button will be 1 if it is currently pressed, or 0 if not currently pressed.

For an axis, the return value will be in the range -1.0 to 1.0. For example, “axis-0” (the X-axis) will return -1.0 (fully left) to 1.0 (fully right).


function OnStart()
  lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
  txt = app.CreateText( "", 1.0, -1, "MultiLine" );
  lay.AddChild( txt );
  app.AddLayout( lay );
  setInterval( ShowState, 200 );
function ShowState()
  var abtn = app.GetJoystickState( 0, "A" );
  var bbtn = app.GetJoystickState( 0, "B" );
  var xaxis = app.GetJoystickState( 0, "axis-0" );
  var yaxis = app.GetJoystickState( 0, "axis-1" );
  msg = "A:" + abtn + " B:" + bbtn + "\n";
  msg += " X-Axis:" + xaxis.toFixed(2) + " Y-Axis:" + yaxis.toFixed(2);
  txt.SetText( msg );

Here is a list of the Joystick button names that can be passed to GetJoystickState:

Button name Description
“Up” DPad Up
“Down” DPad Down
“Left” DPad Left
“Right” DPad Right
“Center” DPad Center
“X”, “Y”, “Z” X, Y and Z Buttons
“A”, “B”, “C” A, B and C Buttons
“Start” Start Button
“ThumbLeft”, “ThumbRight” Left and Right Thumb Buttons

The axis names can be “axis-0” to “axis-9”. “axis-0” and “axis-1” will in most cases be the X and Y axes of the HID controller's main analog stick (i.e. the left stick on an Xbox controller). The remaining axes are for other analog sticks and trigger buttons on the HID controller.

built_in/get_joystick_state.txt · Last modified: 2015/11/02 17:44 (external edit)