Keyboard
Introduction
The Keyboard class provides functionality for getting input data from the physical keyboard. This class is automatically instantiated by and accessible through the InputManager. The Keyboard class is accessible both on a PC as well as on the Xbox 360.
Detecting Keyboard Activity
There are many ways to get data from the keyboard. The following section of code is a series of if-statements which could be used to detect input from the keyboard. Add the following using statements:
In your CustomActivity method:
Controlling Objects With the Keyboard
The Keyboard is commonly used to control objects like in-game characters and the Camera. The following code can be used to quickly control any PositionedObject Add the following using statement:
Assuming positionedObject is a valid PositionedObject (or object inheriting from the PositionedObject class like a Sprite or Camera) add the following code in Update:
For more control over input controlling movement, see the following entry on controlling the camera with the keyboard.
Last updated