Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static List <Joystick> GetJoysticks()
        {
            List <Joystick> ret = new List <Joystick>();

            WinMM.JOYCAPS tmpJoyCaps = new WinMM.JOYCAPS();

            for (uint i = 0; i < MAX_JOYSTICK_DEVICES; i++)
            {
                if (WinMM.joyGetDevCaps((UIntPtr)i, ref tmpJoyCaps, 404) == WinMM.JOYERR_NOERROR)                 // Get joystick info
                {
                    WinMM.JOYINFO joyinfo = new WinMM.JOYINFO();
                    if (WinMM.joyGetPos(i, ref joyinfo) == WinMM.JOYERR_NOERROR)
                    {
                        ret.Add(new Joystick(i));
                    }
                }
            }

            return(ret);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        public Joystick(uint joyNum)
        {
            WinMM.JOYCAPS joyCaps = new WinMM.JOYCAPS();

            if (WinMM.joyGetDevCaps((UIntPtr)joyNum, ref joyCaps, 404) != 0)             //Get joystick info
            {
                throw new Exception("Joystick is not ready.");
            }

            ID   = joyNum;
            Name = joyCaps.szPname;

            HasZ      = (joyCaps.wCaps & WinMM.JOYCAPS_HASZ) != 0;
            HasR      = (joyCaps.wCaps & WinMM.JOYCAPS_HASR) != 0;
            HasU      = (joyCaps.wCaps & WinMM.JOYCAPS_HASU) != 0;
            HasV      = (joyCaps.wCaps & WinMM.JOYCAPS_HASV) != 0;
            HasPOV    = (joyCaps.wCaps & WinMM.JOYCAPS_HASPOV) != 0;
            IsPOV4DIR = (joyCaps.wCaps & WinMM.JOYCAPS_POV4DIR) != 0;
            IsPOVCTS  = (joyCaps.wCaps & WinMM.JOYCAPS_POVCTS) != 0;

            NumberOfAxes    = joyCaps.wNumAxes;
            NumberOfButtons = joyCaps.wNumButtons;
        }