Microsoft DirectX 8.1 (Visual Basic)

Device Object Enumeration

It might be necessary for your application to determine what buttons or axes are available on a given device. To do this, you enumerate the device objects in much the same way as you enumerate devices.

Note  Because of limitations imposed by device drivers, enumeration of keyboard keys and indicator lights is not reliable. Objects might falsely be reported as present. You can get basic information about available keys from the device subtype, but there is no way to determine whether extra objects such as the menu key are available, other than asking the user for input.

You enumerate device objects by calling DirectInputDevice8.GetDeviceObjectsEnum, which returns an instance of the DirectInputEnumDeviceObjects class representing the collection of available device objects that match the requested parameters.

The following code example enumerates axes on a device:

' diDev is a DirectInputDevice object.
 
Dim diEnumObjects As DirectInputEnumDeviceObjects
Set diEnumObjects = diDev.GetDeviceObjectsEnum(DIDFT_AXIS)

The parameter is a combination of flags (just one, in this case) to indicate which type or types of objects to include in the enumeration.

Note  Some of the CONST_DIDFTFLAGS flags are combinations of others; for example, DIDFT_AXIS is equivalent to DIDFT_ABSAXIS Or DIDFT_RELAXIS.

To obtain information about a particular device object, call the methods of a DirectInputDeviceObjectInstance object obtained by calling DirectInputEnumDeviceObjects.GetItem. Information available for a device object includes its name, its type, and its offset in the data structure for the device.

The following code lists the names of the axes enumerated in the previous example:

Dim diDevObjInstance As DirectInputDeviceObjectInstance
Dim i As Integer
For i = 1 To diEnumObjects.GetCount
  Set diDevObjInstance = diEnumObjects.GetItem(i)
  Call List1.AddItem(diDevObjInstance.GetName)
Next i