Exemple #1
0
        public GameController(byte id, int deviceId)
        {
            Id                = id;
            this.deviceId     = deviceId;
            joyInfoEx         = new WindowsMultiMedia.JOYINFOEX();
            joyInfoEx.dwSize  = Marshal.SizeOf(joyInfoEx);
            joyInfoEx.dwFlags = WindowsMultiMedia.JOY_RETURNALL;

            buttonState    = new bool[36];
            oldButtonState = new bool[36];

            fireButtonState = new bool[32];
        }
        public GameControllerManager()
        {
            gameControllers = new List <GameController>();
            int  joystickCount = WindowsMultiMedia.GetJoystickDeviceCount();
            byte controllerId  = 0;

            WindowsMultiMedia.JOYINFOEX joyInfoEx = new WindowsMultiMedia.JOYINFOEX();
            joyInfoEx.dwSize  = Marshal.SizeOf(joyInfoEx);
            joyInfoEx.dwFlags = WindowsMultiMedia.JOY_RETURNALL;

            for (Int32 deviceId = 0; deviceId < joystickCount; deviceId++)
            {
                if (WindowsMultiMedia.GetJoystickState(deviceId, ref joyInfoEx) == WindowsMultiMedia.JOYERR_NOERROR)
                {
                    gameControllers.Add(new GameController(controllerId++, deviceId));
                }
            }
        }