Ejemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            ReleasedKeys.Clear();
            ClickedKeys.Clear();

            KeyboardState state = Keyboard.GetState();

            foreach (IPressedKey pressedKey in new List <IPressedKey>(PressedKeys))
            {
                bool isPressed = false;
                foreach (Keys key in state.GetPressedKeys())
                {
                    if (key == pressedKey.Key)
                    {
                        isPressed = true;
                    }
                }

                if (!isPressed)
                {
                    PressedKeys.Remove(pressedKey);
                    ReleasedKeys.Add(pressedKey.Key);
                }
            }

            foreach (Keys key in state.GetPressedKeys())
            {
                bool isAlreadyPressed = false;

                foreach (IPressedKey pressedKey in PressedKeys)
                {
                    if (key == pressedKey.Key)
                    {
                        isAlreadyPressed = true;
                    }
                }

                if (!isAlreadyPressed)
                {
                    PressedKeys.Add(new PressedKey(key, gameTime.TotalGameTime.TotalSeconds));
                    ClickedKeys.Add(key);
                }
            }
        }
Ejemplo n.º 2
0
 public void Stop()
 {
     PressedKeys.Clear();
     ReleasedKeys.Clear();
     ClickedKeys.Clear();
 }
Ejemplo n.º 3
0
 public bool HasReleased(Keys key)
 {
     return(ReleasedKeys.Contains(key));
 }