Tutorial 1: Using the Keyboard

To prepare for keyboard input, you first create an instance of a DirectInput object. Then you use the IDirectInput::CreateDevice method to create an instance of an IDirectInputDevice interface. The IDirectInputDevice interface methods are used to manipulate the device, set its behavior, and retrieve data.

The tutorial breaks down the required tasks into the following steps:

·Step 1: Creating the DirectInput Object

·Step 2: Creating the DirectInput Keyboard Device

·Step 3: Setting the Keyboard Data Format

·Step 4: Setting the Keyboard Behavior

·Step 5: Gaining Access to the Keyboard

·Step 6: Retrieving Data from the Keyboard

·Step 7: Closing Down the DirectInput System

Adding DirectInput keyboard support to an application is relatively simple, so this tutorial is not accompanied by a complete sample application. All of the tutorial steps are illustrated by code within the text. The related steps for initializing the system are gathered in Sample Function 1: DI_Init. Another function, Sample Function 2: DI_Term, is called whenever the system needs to be closed down.