Пример #1
0
        private void FireEvents(State previous, State current)
        {
            if (StateChanged != null)
            {
                StateChanged(this, previous, current);
            }

            ControllerButtons[] buttons = (ControllerButtons[])Enum.GetValues(typeof(ControllerButtons));

            foreach (ControllerButtons button in buttons)
            {
                bool wasPressed = (previous.Gamepad.Buttons & button) != 0;
                bool isPressed = (current.Gamepad.Buttons & button) != 0;

                if (!wasPressed && isPressed)
                {
                    if (ButtonDown != null)
                    {
                        ButtonDown(this, button);
                    }
                }

                if (wasPressed & !isPressed)
                {
                    if (ButtonUp != null)
                    {
                        ButtonUp(this, button);
                    }
                }
            }
        }
Пример #2
0
 internal static extern int GetState(int dwUserIndex, ref State pState);
Пример #3
0
        /// <summary>
        /// Invoked by the static background thread in XInput to 
        /// poll state and fire events when needed.
        /// </summary>
        internal void PollForEvents()
        {
            if (PollState())
            {
                // make sure we have a lastState available
                if (!firstEventPoll)
                {
                    // make sure our new state isn't some delayed packet
                    if (state.PacketNumber > lastState.PacketNumber)
                    {
                        if (!state.Equals(lastState))
                        {
                            FireEvents(lastState, state);
                        }
                    }
                }

                lastState = this.state;
                firstEventPoll = false;
            }
        }