C# Класс Accord.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 }
Показать файл Открыть проект

Открытые методы

Метод Описание
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.

Описание методов

GetAvailableDevices() публичный статический Метод

Get list of available joysticks connected to the system.
public static GetAvailableDevices ( ) : List
Результат List

GetCurrentStatus() публичный Метод

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
Результат Status

Init() публичный Метод

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].
Результат void

Joystick() публичный Метод

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
Результат System

Joystick() публичный Метод

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].
Результат System