private bool DoButtonClick(int offset, MDI.JoystickUpdate entry)
        {
            var eventArgs = new JoystickEventArgs(this, JoystickState);

            if ((entry.Value & 0x80) != 0)
            {
                JoystickState.Buttons |= offset;
                if (IsBuffered && EventListener != null)
                {
                    return(EventListener.ButtonPressed(eventArgs, 0));
                }
            }
            else
            {
                JoystickState.Buttons &= ~offset;
                if (IsBuffered && EventListener != null)
                {
                    return(EventListener.ButtonReleased(eventArgs, 0));
                }
            }
            return(true);
        }
        private void CaptureXInput()
        {
            var controller = new SXI.Controller((SXI.UserIndex)_joyInfo.XInputDevice);
            var inputState = controller.GetState();

            bool[] axisMoved = { false, false, false, false, false, false, false, false };

            //AXIS
            axisMoved[0] = GetAxisMovement(JoystickState.Axis[0], -inputState.Gamepad.LeftThumbY);
            axisMoved[1] = GetAxisMovement(JoystickState.Axis[1], inputState.Gamepad.LeftThumbX);
            axisMoved[2] = GetAxisMovement(JoystickState.Axis[2], -inputState.Gamepad.RightThumbY);
            axisMoved[3] = GetAxisMovement(JoystickState.Axis[3], inputState.Gamepad.RightThumbX);
            axisMoved[4] = GetAxisMovement(JoystickState.Axis[4], inputState.Gamepad.LeftTrigger * 129 < Joystick.Max_Axis ? inputState.Gamepad.LeftTrigger * 129 : Joystick.Max_Axis);
            axisMoved[5] = GetAxisMovement(JoystickState.Axis[5], inputState.Gamepad.RightTrigger * 129 < Joystick.Max_Axis ? inputState.Gamepad.RightTrigger * 129 : Joystick.Max_Axis);

            //POV
            Pov.Position previousPov = JoystickState.Povs[0].Direction;
            Pov.Position pov         = Pov.Position.Centered;
            if ((inputState.Gamepad.Buttons & SXI.GamepadButtonFlags.DPadUp) != 0)
            {
                pov |= Pov.Position.North;
            }
            else if ((inputState.Gamepad.Buttons & SXI.GamepadButtonFlags.DPadDown) != 0)
            {
                pov |= Pov.Position.South;
            }
            if ((inputState.Gamepad.Buttons & SXI.GamepadButtonFlags.DPadLeft) != 0)
            {
                pov |= Pov.Position.West;
            }
            else if ((inputState.Gamepad.Buttons & SXI.GamepadButtonFlags.DPadRight) != 0)
            {
                pov |= Pov.Position.East;
            }
            JoystickState.Povs[0].Direction = pov;

            //BUTTONS
            // Skip the first 4 as they are the DPad.
            var previousButtons = JoystickState.Buttons;

            for (int i = 0; i < 12; i++)
            {
                if (((int)inputState.Gamepad.Buttons & (1 << (i + 4))) != 0)
                {
                    JoystickState.Buttons |= 1 << (i + 4);
                }
                else
                {
                    JoystickState.Buttons &= ~(1 << (i + 4));
                }
            }

            //Send Events
            if (IsBuffered && EventListener != null)
            {
                var joystickEvent = new JoystickEventArgs(this, JoystickState);

                // Axes
                for (int index = 0; index < axisMoved.Length; index++)
                {
                    if (axisMoved[index] == true && EventListener.AxisMoved(joystickEvent, index))
                    {
                        return;
                    }
                }

                //POV
                if (previousPov != pov && !EventListener.PovMoved(joystickEvent, 0))
                {
                    return;
                }

                //Buttons
                for (int i = 4; i < 16; i++)
                {
                    if (((previousButtons & (1 << i)) == 0) && JoystickState.IsButtonDown(i))
                    {
                        if (!EventListener.ButtonPressed(joystickEvent, i))
                        {
                            return;
                        }
                    }
                    else if (((previousButtons & (1 << i)) != 0) && !JoystickState.IsButtonDown(i))
                    {
                        if (!EventListener.ButtonReleased(joystickEvent, i))
                        {
                            return;
                        }
                    }
                }
            }
        }