Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public sealed class InputHandler : GameComponent, IInputManager
- {
- public InputHandler(Game game)
- : base(game)
- {
- }
- // assigned in Update() call
- KeyboardState lastState;
- /// <summary>
- /// Überprüft ob eine Taste gedrückt worden ist.
- /// </summary>
- public bool IsKeyPressed(Keys key)
- {
- Keys[] lastKeys = this.lastState.GetPressedKeys();
- return IsKeyDown(key) && !lastKeys.Contains(key);
- }
- /// <summary>
- /// Überprüft, ob eine Taste momentan gedrückt ist.
- /// </summary>
- public bool IsKeyDown(Keys key)
- {
- KeyboardState currentState = Keyboard.GetState();
- Keys[] currentKeys = currentState.GetPressedKeys();
- return currentKeys.Contains(key);
- }
- public override void Update(GameTime gameTime)
- {
- lastState = Keyboard.GetState();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment