예제 #1
0
        private void FireKeyboardEvents()
        {
            foreach (var key in KeyList)
            {
                // Is the key currently down?
                if (CurrentKeyboardState.IsKeyDown(key))
                {
                    // Fire the OnKeyDown event
                    if (OnKeyDown != null)
                    {
                        OnKeyDown(this, new KeyboardEventArgs(key, CurrentKeyboardState,
                                                              PrevKeyboardState));
                    }
                }

                // Has the key been released? (Was down and is now up)
                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key))
                {
                    // Fire the OnKeyUp event
                    if (OnKeyUp != null)
                    {
                        OnKeyUp(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }

                // Has the key been pressed? (Was up and is now down)
                if (PrevKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key))
                {
                    if (OnKeyPressed != null)
                    {
                        OnKeyPressed(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }
            }
        }
        private void FireKeyboardEvents()
        {
            foreach (Keys key in KeyList)
            {
                if (CurrentKeyboardState.IsKeyDown(key))
                {
                    if (OnKeyDown != null)
                    {
                        OnKeyDown(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }

                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key))
                {
                    if (OnKeyUp != null)
                    {
                        OnKeyUp(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }

                if (PrevKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key))
                {
                    if (OnKeyPressed != null)
                    {
                        OnKeyPressed(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }
            }
        }
예제 #3
0
        private void FireKeyboardEvents()
        {
            // Check through each key in the key list
            foreach (Keys key in KeyList)
            {
                // Is the key currently down?
                if (CurrentKeyboardState.IsKeyDown(key))
                {
                    // Fire the OnKeyDown event
                    OnKeyDown?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                }

                // Has the key been released? (Was down and is now up)
                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key))
                {
                    OnKeyUp?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                }

                // Has the key been pressed? (Was up and is now down)
                if (PrevKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key))
                {
                    OnKeyPressed?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                }
            }
        }
 public override void Run(GameTime gameTime, Entity entity)
 {
     if (world.IsGameOver())
     {
         if (Mouse.GetState().RightButton == ButtonState.Pressed && PrevMouseState.RightButton == ButtonState.Released)
         {
             world.Game.ResetGame();
         }
     }
     if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
         Keyboard.GetState().IsKeyDown(Keys.Escape) && PrevKeyboardState.IsKeyUp(Keys.Escape))
     {
         world.Game.Exit();
     }
     if (Keyboard.GetState().IsKeyDown(Keys.OemCloseBrackets) && PrevKeyboardState.IsKeyUp(Keys.OemCloseBrackets))
     {
         world.Background.CycleBackground();
     }
     if (Keyboard.GetState().IsKeyDown(Keys.F) && PrevKeyboardState.IsKeyUp(Keys.F))
     {
         world.Game.ToggleFullScreen();
     }
 }
예제 #5
0
 internal bool WasKeyPressed(Keys key) => PrevKeyboardState.IsKeyUp(key) && KeyboardState.IsKeyDown(key);
예제 #6
0
 public bool KeyPressed(Keys i_Key)
 {
     return(PrevKeyboardState.IsKeyUp(i_Key) && KeyboardState.IsKeyDown(i_Key));
 }
예제 #7
0
 /// <summary>
 /// Checks if the key is pressed this tick but not the last.
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static bool IsKeyPressed(Keys key)
 {
     return(KeyboardState.IsKeyDown(key) && PrevKeyboardState.IsKeyUp(key));
 }