public Init ( int id ) : void | ||
id | int | Joystick's ID to initialize, [0, 15]. |
return | void |
public void Init( int id )
{
if ( ( id < 0 ) || ( id > 15 ) )
{
throw new ArgumentException( "Invalid joystick ID was specified." );
}
JoystickAPI.JOYCAPS joyCaps = new JoystickAPI.JOYCAPS( );
if ( JoystickAPI.joyGetDevCapsW( id, joyCaps,
System.Runtime.InteropServices.Marshal.SizeOf( joyCaps ) ) != JoystickAPI.ResultCode.NoError )
{
throw new NotConnectedException( "The requested joystick is not connected to the system." );
}
info = new DeviceInfo( id, joyCaps );
}
private bool GetAvaliableJoystickControls() { // enumerate available devices List<Joystick.DeviceInfo> devices = Joystick.GetAvailableDevices(); foreach (Joystick.DeviceInfo di in devices) { this.send_UI_message(string.Format("{0} : {1} ({2} axes, {3} buttons)", di.ID, di.Name, di.Axes, di.Buttons)); } try { // create new joystick and initialize it joystick = new Joystick(0); // get its current status joystick.Init(0); return true; } catch (Exception ex) { this.send_UI_message("No joystick found." + ex.Message.ToString()); return false; } }