One problem you'll run into very quickly is putting too much game logic into your input class. You're better off creating an intermediate class that handles game logic and input. Your input classes should be just wrappers around the various devices and provide some utility functions.
Something like this:
class MyGame : Game
Input _input; // Utility class that provides helpers for input
UnitManager _units; // Tracker for units
InputHandler _inputHandler; // Connects game units with input
protected override void Initialize()
_input = new Input();
_units = new UnitManager(this);
// InputHandler will probably want the game, units, and the input helper.
// (Or it internally manages the input util class)
_inputHandler = new InputHandler(this, _input, _units);
protected override void Update(GameTime time)
_input.Update(time); // Update input states - new clicks, presses, etc...
_units.Update(time); // AI moves
_inputHandler(time); // Check input for clicks, button presses, etc...
Edit: Further examples...
The Input class I use is just a wrapper and some utility functions.
InputManager - Just holds three helpers for keyboard, mouse, and controller. I make this relatively global by creating it in my Game instance and passing it down into the various screens and components.
ControllerHelper, KeyboardHelper, MouseHelper - These all get updated and store the last and current state so you can have easier helpers like
Input.Keyboard.IsKeyHeld(Keys.Space). Makes checking and storing that information much easier - your logic class doesn't have to concern itself with handling input states, just checking for state changes.
I use an entity system which is a whole other topic, but it gives me the InputHandler class mentioned above. Here's some roughcode for it:
public class InputHandler
MyGame _game; // Assuming Input is a property here
// Constructor - pass any dependencies here
public InputHandler(MyGame game, Player player)
_game = game;
_player = player;
// Update, as usual
public void Update(GameTime time)
_player.Position.X += 1;
_player.Position.X -= 1;
// And so on...
// You probably wouldn't be using 1 as a speed, factor in
// the elapsed time since the last update for smoother movement
// in case of slow-downs and add in a speed variable to
// control that.
// XBox controller input is pretty much the same, just you can
// get 0.0 - 1.0 Vector2's from the thumbsticks.
// Not all your input has to go here either. If you use a game
// state system, each game state might have it's own InputHandler
// class (ie, a menu state would handle up/down differently than
// in game.
// Elsewhere would be a camera class that takes the player as
// a dependency and updates the view matrix from player position
// and rotation.