Platform SDK: DirectX

Step 2: Get Joystick Capabilities

[C++]

This topic pertains only to application development in Visual Basic. See DirectInput C/C++ Tutorials.

[Visual Basic]

Getting basic information about the buttons, axes, and point-of-view controllers on the device requires a simple call to DirectInputDevice.GetCapabilities:

Dim joyCaps As DIDEVCAPS
Call diDev.GetCapabilities joyCaps

The Joystick sample is interested only in the number of buttons and point-of-view controllers on the device. Although the DIDEVCAPS type also reports the number of axes on the device, it does not reveal anything about what those axes are. For this information, the sample calls the IdentifyAxes procedure:

Sub IdentifyAxes(diDev As DirectInputDevice)

   Dim didoEnum As DirectInputEnumDeviceObjects
   Dim dido As DirectInputDeviceObjectInstance
   Dim i As Integer
   
   For i = 1 To 8
     AxisPresent(i) = False
   Next
   

After declaring a few variables and clearing out the AxisPresent array (which stores Boolean values for each possible axis), the procedure goes on to enumerate all device objects:

   Set didoEnum = diDev.GetDeviceObjectsEnum(DIDFT_AXIS)

It then queries each DirectInputDeviceObjectInstance for its offset within the data format that was established earlier by the call to DirectInputDevice.SetCommonDataFormat. This offset identifies the conventional role or type of the axis; for instance, you know that a DIJOFS_RZ axis likely corresponds to a twisting motion on the main stick. Keep in mind, though, that device drivers are free to assign any designation to an axis. It is always a good idea to allow users to change the mapping of the axes to actions within your application.

    For i = 1 To didoEnum.GetCount
        Set dido = didoEnum.GetItem(i)
        Select Case dido.GetOfs
            Case DIJOFS_X
                AxisPresent(1) = True
            Case DIJOFS_Y
                AxisPresent(2) = True
' and so on
.
.
.
        End Select
    Next
End Sub

The application now passes the event handle created earlier to the device, so that notifications will be sent to the form when an input event takes place.

Call diDev.SetEventNotification(EventHandle)

Next: Step 3: Set Joystick Properties