Back

GetJoystickState

Hello World

Returns the state of a connected joystick.

app.GetJoystickState( id, key ) → number

The key can have many values depending on the used controller. The axis-n keys are for different joystick x/y/z axes or the D-Pad - you will best try which key stands for which button with the attached example.

See Also: GetJoystickName

Example - Show States

function OnStart()
{
    lay = app.CreateLayout( "linear" );

    txt = app.CreateText( "", 1, 1, "monospace,left,multiline" );
    lay.AddChild( txt );

    app.AddLayout( lay );

    app.SetDebug( "console" );
    app.Animate( ShowStates, 10 );
}

function ShowStates()
{
    var keys = "A|B|C|X|Y|Z|R1|L1|Up|Down|Left|Right|Start|ThumbLeft|ThumbRight|" +
        "axis-0|axis-1|axis-2|axis-3|axis-4|axis-5|axis-6|axis-7|axis-8|axis-9";

    keys = keys.split("|");

    var lst = [];
    for(var i in keys)
    {
        var state = app.GetJoystickState(0, keys[i]);
        lst.push(keys[i] + ": " + state);
    }

    txt.SetText( lst.join( "\n" ) );
}
    Copy     Copy All       Run      
number: integer
string: “A” or “B” or “C” or “X” or “Y” or “Z” or “R1” or “L1” or “Left” or “Right” or “Up” or “Down” or “Start” or “ThumbLeft” or “ThumbRight” or “axis-0..9”