C# Class AForge.Controls.Joystick

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

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:

// 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 }
显示文件 Open project: holisticware-admin/MonoVersal.AForgeNET Class Usage Examples

Public Methods

Method Description
GetAvailableDevices ( ) : List

Get list of available joysticks connected to the system.

GetCurrentStatus ( ) : Status

Get joystick's status.

Before using this method the joystick object needs to be initialized using Init method or Joystick(int) constructor.

Init ( int id ) : void

Initialize joystick with the specified ID.

Joystick ( ) : System

Initializes a new instance of the Joystick class.

This constructor does not make initialization of any joystick device, so Init method should be used before querying joystick status or properties.

Joystick ( int id ) : System

Initializes a new instance of the Joystick class.

This constructor initializes joystick with specified ID using Init method, so the object becomes ready for querying joystick's status.

Method Details

GetAvailableDevices() public static method

Get list of available joysticks connected to the system.
public static GetAvailableDevices ( ) : List
return List

GetCurrentStatus() public method

Get joystick's status.

Before using this method the joystick object needs to be initialized using Init method or Joystick(int) constructor.

The requested joystick is not connected to the system. Joystick was not initialized.
public GetCurrentStatus ( ) : Status
return Status

Init() public method

Initialize joystick with the specified ID.

Invalid joystick ID was specified. It must be in [0, 15] range. The requested joystick is not connected to the system.
public Init ( int id ) : void
id int Joystick's ID to initialize, [0, 15].
return void

Joystick() public method

Initializes a new instance of the Joystick class.

This constructor does not make initialization of any joystick device, so Init method should be used before querying joystick status or properties.

public Joystick ( ) : System
return System

Joystick() public method

Initializes a new instance of the Joystick class.

This constructor initializes joystick with specified ID using Init method, so the object becomes ready for querying joystick's status.

public Joystick ( int id ) : System
id int Joystick ID to initialize, [0, 15].
return System