Пример #1
0
        private static Joystick LoadJoystick(int index)
        {
            Joystick stick = new Joystick();

            stick.ID = index;

            stick.Capabilities = new WinMMAPI.JOYCAPS();
            int size = Marshal.SizeOf(stick.Capabilities);

            WinMMAPI.ResultCode result = WinMMAPI.joyGetDevCapsA(index, stick.Capabilities, size);

            if (result != WinMMAPI.ResultCode.NoError || stick.Capabilities.Name == string.Empty)
            {
                return(null);
            }

            for (int a = 0; a < stick.Capabilities.axesNumber; a++)
            {
                stick.Axes.Add(GetAxisLabel(a));
            }

            for (int b = 0; b < stick.Capabilities.buttonsNumber; b++)
            {
                stick.Buttons.Add(GetButtonLabel(b));
            }

            return(stick);
        }
Пример #2
0
        public List <bool> GetButtonStates()
        {
            WinMMAPI.JOYINFOEX info = new WinMMAPI.JOYINFOEX();
            info.flags = WinMMAPI.JoyPosFlags.ReturnAll;

            WinMMAPI.joyGetPosEx(ID, info);
            return(UpdateButtonState(info));
        }
Пример #3
0
        public List <double> GetAxisStates()
        {
            WinMMAPI.JOYINFOEX info = new WinMMAPI.JOYINFOEX();
            info.flags = WinMMAPI.JoyPosFlags.ReturnAll;

            WinMMAPI.joyGetPosEx(ID, info);
            return(UpdateAxisState(info));
        }
Пример #4
0
        public void StartCapture()
        {
            WinMMAPI.JOYINFOEX info = new WinMMAPI.JOYINFOEX();
            info.flags = WinMMAPI.JoyPosFlags.ReturnAll;

            WinMMAPI.joyGetPosEx(ID, info);

            LastAxisPositions = UpdateAxisState(info);
            LastButtonStates  = UpdateButtonState(info);
        }
Пример #5
0
        public static Joystick[] GetDevices()
        {
            if (Devices.Count == 0)
            {
                for (int i = 0; i < WinMMAPI.joyGetNumDevs(); i++)
                {
                    Joystick stick = LoadJoystick(i);
                    if (stick != null)
                    {
                        Devices.Add(stick);
                    }
                }
            }

            return(Devices.ToArray());
        }