Microsoft DirectX 8.1 (Visual Basic)

Step 2: Getting Joystick Capabilities

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

Dim joyCaps As DIDEVCAPS
diDev.GetCapabilities joyCaps

The Joystick Sample needs only 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 its own IdentifyAxes procedure. It first declares its variables and initializes an array that will hold Boolean values indicating the presence or absence of each possible axis.

Sub IdentifyAxes(diDev As DirectInputDevice8)

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

The procedure goes on to enumerate device objects on the device. The DIDFT_AXIS value will restrict the enumeration to axes.

    Set didoEnum = diDev.GetDeviceObjectsEnum(DIDFT_AXIS)

Each DirectInputDeviceObjectInstance is then queried for its offset within the data format that was established earlier by the call to DirectInputDevice8.SetCommonDataFormat. This offset identifies the conventional role or type of the axis; for instance, a GUID_RzAxis 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.

    Dim sGuid as String
    For i = 1 To didoEnum.GetCount
        Set dido = didoEnum.GetItem(i)
        sGuid = didoEnum.GetItem(i)

        Select Case sGuid
            Case "GUID_Xaxis"
                AxisPresent(1) = True
            Case "GUID_Yaxis"
                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, you set the joystick properties in Step 3: Setting Joystick Properties.