Tutorial 3: Using the Joystick

This tutorial shows you how to enumerate joysticks on a system and set up two or more joysticks for input. Code samples are based on the Space Donuts application in the SDK\SAMPLES directory of the DirectX code samples of the Platform SDK References. The method calls are in the C form.

The preliminary step of setting up the DirectInput system and the final step of closing it down are the same for any application and are covered in Tutorial 1: Using the Keyboard.

The first step in the tutorial is to enumerate devices; that is, to see what joysticks are available. As part of this process you initialize each joystick device and set its desired characteristics. You then use the IDirectInputDevice interface methods to retrieve data from each joystick.

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

·Step 1: Enumerating the Joysticks

·Step 2: Creating the DirectInput Joystick Device

·Step 3: Setting the Joystick Data Format

·Step 4: Setting the Joystick Behavior

·Step 5: Gaining Access to the Joystick

·Step 6: Retrieving Data from the Joystick