Click or drag to resize
Accord.NET (logo)

Joystick Class

The class provides simple API for enumerating available joysticks and checking their current status.
Inheritance Hierarchy
SystemObject
  Accord.ControlsJoystick

Namespace:  Accord.Controls
Assembly:  Accord.Controls (in Accord.Controls.dll) Version: 3.8.0
Syntax
public class Joystick
Request Example View Source

The Joystick type exposes the following members.

Constructors
  NameDescription
Public methodJoystick
Initializes a new instance of the Joystick class.
Public methodJoystick(Int32)
Initializes a new instance of the Joystick class.
Top
Properties
  NameDescription
Public propertyInfo
Information about initialized joystick.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodStatic memberGetAvailableDevices
Get list of available joysticks connected to the system.
Public methodGetCurrentStatus
Get joystick's status.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodInit
Initialize joystick with the specified ID.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
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:

// 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
}
See Also