예제 #1
0
        /// <summary>
        /// Get joystick's status.
        /// </summary>
        ///
        /// <returns>Returns current status of initialized joystick, which provides information
        /// about current state of all axes, buttons and point of view.</returns>
        ///
        /// <remarks><para><note>Before using this method the joystick object needs to be initialized
        /// using <see cref="Init"/> method or <see cref="Joystick(int)"/> constructor.</note></para></remarks>
        ///
        /// <exception cref="NotConnectedException">The requested joystick is not connected to the system.</exception>
        /// <exception cref="ApplicationException">Joystick was not initialized.</exception>
        ///
        public Status GetCurrentStatus()
        {
            JoystickAPI.JOYINFOEX ji = new JoystickAPI.JOYINFOEX();

            ji.size  = System.Runtime.InteropServices.Marshal.SizeOf(ji);
            ji.flags = (Info.capabilities.axesNumber > 5) ? JoystickAPI.JoyPosFlags.ReturnAll :
                       requestFlags[Info.capabilities.axesNumber];

            if (JoystickAPI.joyGetPosEx(Info.ID, ji) != JoystickAPI.ResultCode.NoError)
            {
                throw new NotConnectedException("The requested joystick is not connected to the system.");
            }

            return(new Status(ji, Info.capabilities));
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
 internal Status(JoystickAPI.JOYINFOEX status, JoystickAPI.JOYCAPS capabilities)
 {
     this.status = status;
     this.capabilities = capabilities;
 }
예제 #5
0
 internal DeviceInfo(int id, JoystickAPI.JOYCAPS joyCaps)
 {
     ID = id;
     capabilities = joyCaps;
 }