Esempio n. 1
0
 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, Marshal.SizeOf(jOYCAPS)) != 0)
     {
         throw new NotConnectedException("The requested joystick is not connected to the system.");
     }
     info = new DeviceInfo(id, jOYCAPS);
 }
Esempio n. 2
0
        public static List <DeviceInfo> GetAvailableDevices()
        {
            List <DeviceInfo> list = new List <DeviceInfo>();
            int cbjc = Marshal.SizeOf(typeof(JoystickAPI.JOYCAPS));
            int num  = JoystickAPI.joyGetNumDevs();

            for (int i = 0; i < num; i++)
            {
                JoystickAPI.JOYCAPS jOYCAPS = new JoystickAPI.JOYCAPS();
                if (JoystickAPI.joyGetDevCapsW(i, jOYCAPS, cbjc) == JoystickAPI.ResultCode.NoError)
                {
                    list.Add(new DeviceInfo(i, jOYCAPS));
                }
            }
            return(list);
        }
Esempio n. 3
0
        /// <summary>
        /// Initialize joystick with the specified ID.
        /// </summary>
        ///
        /// <param name="id">Joystick's ID to initialize, [0, 15].</param>
        ///
        /// <remarks><para></para></remarks>
        ///
        /// <exception cref="ArgumentException">Invalid joystick ID was specified. It must be in [0, 15] range.</exception>
        /// <exception cref="NotConnectedException">The requested joystick is not connected to the system.</exception>
        ///
        public void Init(int id)
        {
            if ((id < 0) || (id > 15))
            {
                throw new ArgumentException("Invalid joystick ID was specified.");
            }

            var 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);
        }
Esempio n. 4
0
        /// <summary>
        /// Get list of available joysticks connected to the system.
        /// </summary>
        ///
        /// <returns>Returns list containing information about available joysticks connected to
        /// the system.</returns>
        ///
        public static List <DeviceInfo> GetAvailableDevices()
        {
            var devices     = new List <DeviceInfo>();
            var joyCapsSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(JoystickAPI.JOYCAPS));

            // get number of devices
            var devicesCount = JoystickAPI.joyGetNumDevs();

            // check all devices
            for (var i = 0; i < devicesCount; i++)
            {
                var joyCaps = new JoystickAPI.JOYCAPS();

                if (JoystickAPI.joyGetDevCapsW(i, joyCaps, joyCapsSize) == JoystickAPI.ResultCode.NoError)
                {
                    devices.Add(new DeviceInfo(i, joyCaps));
                }
            }

            return(devices);
        }
Esempio n. 5
0
 internal Status(JoystickAPI.JOYINFOEX status, JoystickAPI.JOYCAPS capabilities)
 {
     this.status = status;
     this.capabilities = capabilities;
 }
Esempio n. 6
0
        /// <summary>
        /// Initialize joystick with the specified ID.
        /// </summary>
        /// 
        /// <param name="id">Joystick's ID to initialize, [0, 15].</param>
        /// 
        /// <remarks><para></para></remarks>
        /// 
        /// <exception cref="ArgumentException">Invalid joystick ID was specified. It must be in [0, 15] range.</exception>
        /// <exception cref="NotConnectedException">The requested joystick is not connected to the system.</exception>
        /// 
        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);
        }
Esempio n. 7
0
        /// <summary>
        /// Get list of available joysticks connected to the system.
        /// </summary>
        /// 
        /// <returns>Returns list containing information about available joysticks connected to
        /// the system.</returns>
        /// 
        public static List<DeviceInfo> GetAvailableDevices()
        {
            List<DeviceInfo> devices = new List<DeviceInfo>();
            int joyCapsSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(JoystickAPI.JOYCAPS));

            // get number of devices
            int devicesCount = JoystickAPI.joyGetNumDevs();
            // check all devices
            for (int i = 0; i < devicesCount; i++)
            {
                JoystickAPI.JOYCAPS joyCaps = new JoystickAPI.JOYCAPS();

                if (JoystickAPI.joyGetDevCapsW(i, joyCaps, joyCapsSize) == JoystickAPI.ResultCode.NoError)
                {
                    devices.Add(new DeviceInfo(i, joyCaps));
                }
            }

            return devices;
        }
Esempio n. 8
0
 internal DeviceInfo(int id, JoystickAPI.JOYCAPS joyCaps)
 {
     ID = id;
     capabilities = joyCaps;
 }
Esempio n. 9
0
 internal Status(JoystickAPI.JOYINFOEX status, JoystickAPI.JOYCAPS capabilities)
 {
     this.status       = status;
     this.capabilities = capabilities;
 }
Esempio n. 10
0
 internal DeviceInfo(int id, JoystickAPI.JOYCAPS joyCaps)
 {
     ID           = id;
     capabilities = joyCaps;
 }