Exemple #1
0
        override public void Update()
        {
            if (GamePadInput.GetGamePad(this.playerIndex).IsConnected)
            {
                Position = StickValue();

                if (timerAutoRepeat.Running)
                {
                    timerAutoRepeat.Update();
                }
            }
            else
            {
                Reset();
            }
        }
Exemple #2
0
        public static void Update()
        {
            int indexTimer  = 0;
            int countTimers = timers.Count; // cache this as to not run new ones this cycle

            while (indexTimer < countTimers)
            {
                GameTimer gameTimer = timers[indexTimer] as GameTimer;
                if (gameTimer.Update())
                {
                    countTimers--; // one less now
                }
                else
                {
                    indexTimer++;
                }
            }
        }
        override public void Update()
        {
            if (GamePadInput.GetGamePad(this.playerIndex).IsConnected)
            {
                bool keyIsPressed = false;

                Keys[] currentPressedKeys = chatpadStates[(int)this.playerIndex].GetPressedKeys();

                // walk both sets of keys; the prev and current
                // which are in order and
                // trigger repeat, press, and release events
                int indexPrev = 0;
                int indexCurr = 0;

                Keys keyPrev;
                Keys keyCurr;

                // while either set still has keys
                while (indexPrev < this.pressedKeys.Length || indexCurr < currentPressedKeys.Length)
                {
                    if (indexPrev < this.pressedKeys.Length)
                    {
                        keyPrev = this.pressedKeys[indexPrev];
                    }
                    else
                    {
                        keyPrev = (Keys)255;// not valid, reached end of this set
                    }
                    if (indexCurr < currentPressedKeys.Length)
                    {
                        keyCurr = currentPressedKeys[indexCurr];
                    }
                    else
                    {
                        keyCurr = (Keys)255; // not valid, reached end of this set
                    }

                    if (keyPrev == keyCurr)
                    {
                        indexPrev++;
                        indexCurr++;
                        // key still pressed
                        if (!IsModifierKey(keyCurr))
                        {
                            keyIsPressed = true;
                        }
                    }
                    else if (keyPrev < keyCurr)
                    {
                        indexPrev++;
                        // key was released
                        if (ReleasePress != null)
                        {
                            ReleasePress(this, new KeyboardKeyEventArgs(keyPrev));
                        }
                    }
                    else
                    {
                        indexCurr++;
                        // new key pressed
                        if (Press != null)
                        {
                            Press(this, new KeyboardKeyEventArgs(keyCurr));
                        }
                        if (CharInput != null)
                        {
                            OnChar(keyCurr);
                        }
                        if (!IsModifierKey(keyCurr))
                        {
                            keyIsPressed = true;
                        }
                    }
                }

                // update generalized state
                if (keyIsPressed)
                {
                    if (state == KeyCommandState.ReleasePress)
                    {
                        // NOTE: do not call Start on this timer, it is being used in a caller update model
                        timerAutoRepeat.Reset(timeFirstAutoRepeat);
                        state = KeyCommandState.Press;
                    }
                }
                else
                {
                    if (state != KeyCommandState.ReleasePress)
                    {
                        timerAutoRepeat.Clear();
                        state = KeyCommandState.ReleasePress;
                    }
                }

                this.pressedKeys = currentPressedKeys;

                if (timerAutoRepeat.Running)
                {
                    timerAutoRepeat.Update();
                }
            }
            else
            {
                Reset();
            }
        }