The class provides simple API for enumerating available joysticks and checking their current status.

Namespace:  AForge.Controls
Assembly:  AForge.Controls (in AForge.Controls.dll) Version: 2.2.5.0 (2.2.5.0)

Syntax

C#
public class Joystick

Remarks

The class provides simple access to joysticks (game controllers) through using Win32 API, which allows to enumerate available devices and query their status (state of all buttons, axes, etc).

Sample usage:

CopyC#
// enumerate available devices
List<Joystick.DeviceInfo> devices = Joystick.GetAvailableDevices( );

foreach ( Joystick.DeviceInfo di in devices )
{
    System.Diagnostics.Debug.WriteLine(
        string.Format( "{0} : {1} ({2} axes, {3} buttons)",
            di.ID, di.Name, di.Axes, di.Buttons ) );
}


// create new joystick and initialize it
Joystick joystick = new Joystick( 0 );
// get its current status
Joystick.Status status = joystick.GetCurrentStatus( );
// check if 1st button is pressed
if ( status.IsButtonPressed( Joystick.Buttons.Button1 ) )
{
    // 1st button is pressed
}

Inheritance Hierarchy

System..::.Object
  AForge.Controls..::.Joystick

See Also