XNA Keyboard & mouse handling

XNA provides anumber of classes to help perform keyboard handling

Keyboard: an abstration of the keyboard

Keyboard.GetState();

 

Keyboardstate: represents the current state of the keyboard

kb.IsKeyDown(Keys.Escape)

 

            KeyboardState kb=Keyboard.GetState();

            if(kb.IsKeyDown(Keys.Escape))
                this.Exit();

 

Mouse state is handled by the MouseState class

 

            MouseState ms = Mouse.GetState();

            int xpos = ms.X; // get x position

            if(ms.LeftButton==ButtonState.Pressed){ ... }