Back

GetJoystickState

GetJoystickState returns the state of a button or axis of a HID Joystick or Gamepad. This method can get the state of multiple HID controllers currently connected to the 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 of -1.0 to 1.0. For example, "axis-0" (the X-axis) will return -1.0 (fully left) to 1.0 (fully right).

app.GetJoystickState( id, key ) -> unknown

Example - Example



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 );
}
    Copy     Copy All       Run      

unknown