Пример #1
0
        public JoystickStatus PollStatus()
        {
            JoyInfoEx info = new JoyInfoEx();

            info.Size      = (uint)Marshal.SizeOf(info);
            info.SetFields = JoySetFields.ReturnAll;

            JoyResult result = NativeMethods.JoyGetPosEx(_info.Id, ref info);

            if (result != JoyResult.OK)
            {
                throw new InvalidOperationException("Could not poll joystick status. Error returned: " + result);
            }

            return(new JoystickStatus(_info, info));
        }
Пример #2
0
        public static Collection <JoystickInfo> GetJoysticks()
        {
            Collection <JoystickInfo> ret = new Collection <JoystickInfo>();
            int count = NativeMethods.JoyGetNumDevices();
            int size  = Marshal.SizeOf(typeof(JoyCapabilitiesInfo));

            for (int i = 0; i < count; i++)
            {
                JoyCapabilitiesInfo joystick = new JoyCapabilitiesInfo();

                JoyResult result = NativeMethods.JoyGetDevCapsW(i, ref joystick, size);

                if (result == JoyResult.OK)
                {
                    ret.Add(new JoystickInfo(i, joystick));
                }
            }

            return(ret);
        }