Exemplo n.º 1
0
        /// <summary>
        /// Gets the State.
        /// </summary>
        /// <returns>JoystickState.</returns>
        public JoystickState GetState()
        {
            if (JoystickInterops.joyGetNumDevs() > 0)
            {
                var jie = new JoyInfoEx {
                    dwFlags = (int)JoyFlags.JOY_RETURNALL
                };
                jie.dwSize = (uint)Marshal.SizeOf(jie);

                Try(JoystickInterops.joyGetPosEx(0, ref jie));

                var buttonStates = new Dictionary <int, bool>();

                for (int i = 1; i <= 32; i++)
                {
                    int button = 2 ^ (i - 1);
                    buttonStates.Add(i, ((jie.dwButtons & button) != 0));
                }

                return(new JoystickState(jie.dwXpos, jie.dwYpos, jie.dwZpos, jie.dwRpos, jie.dwUpos, jie.dwVpos,
                                         new PointOfView(jie.dwPOV / 100d), buttonStates));
            }

            throw new InvalidOperationException("Joystick not connected.");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the State.
        /// </summary>
        /// <returns>JoystickState.</returns>
        public JoystickState GetState()
        {
            if (JoystickInterops.joyGetNumDevs() > 0)
            {
                var jie = new JoyInfoEx {dwFlags = (int) JoyFlags.JOY_RETURNALL};
                jie.dwSize = (uint) Marshal.SizeOf(jie);

                Try(JoystickInterops.joyGetPosEx(0, ref jie));

                var buttonStates = new Dictionary<int, bool>();

                for (int i = 1; i <= 32; i++)
                {
                    int button = 2 ^ (i - 1);
                    buttonStates.Add(i, ((jie.dwButtons & button) != 0));
                }

                return new JoystickState(jie.dwXpos, jie.dwYpos, jie.dwZpos, jie.dwRpos, jie.dwUpos, jie.dwVpos,
                    new PointOfView(jie.dwPOV/100d), buttonStates);
            }

            throw new InvalidOperationException("Joystick not connected.");
        }
Exemplo n.º 3
0
 internal static extern uint joyGetPosEx(uint uJoyId, ref JoyInfoEx pjiex);
Exemplo n.º 4
0
 internal static extern uint joyGetPosEx(uint uJoyId, ref JoyInfoEx pjiex);