AForge.Controls.Joystick.Init C# (CSharp) Метод

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
        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 );
        }

Usage Example

Пример #1
0
        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;

            }
        }