using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; namespace EvilSatellites { public class InputManager { private KeyboardState OldKeyState; private KeyboardState NewKeyState; private GamePadState OldPadState; private GamePadState NewPadState; public InputManager() { OldKeyState = Keyboard.GetState(); NewKeyState = Keyboard.GetState(); OldPadState = GamePad.GetState(PlayerIndex.One); NewPadState = GamePad.GetState(PlayerIndex.One); } public void Update() { OldKeyState = NewKeyState; NewKeyState = Keyboard.GetState(); OldPadState = NewPadState; NewPadState = GamePad.GetState(PlayerIndex.One); } public bool IsJustPressed(Keys key) { return (NewKeyState.IsKeyDown(key) && !OldKeyState.IsKeyDown(key)); } public bool IsJustReleased(Keys key) { return !NewKeyState.IsKeyDown(key) && OldKeyState.IsKeyDown(key); } public bool IsPressed(Keys key) { return NewKeyState.IsKeyDown(key); } public bool IsReleased(Keys key) { return NewKeyState.IsKeyUp(key); } public bool IsJustPressed(Buttons key) { return (NewPadState.IsButtonDown(key) && !OldPadState.IsButtonDown(key)); } public bool IsJustReleased(Buttons key) { return !NewPadState.IsButtonDown(key) && OldPadState.IsButtonDown(key); } public bool IsPressed(Buttons key) { return NewPadState.IsButtonDown(key); } public bool IsReleased(Buttons key) { return !NewPadState.IsButtonDown(key); } } }