Microsoft DirectX 8.1 (Visual Basic) |
Before you begin asking for input from a device, you need to know something about its capabilities. Does the joystick have a point-of-view hat? Is the mouse currently attached to the user's computer?
Such questions are answered with a call to the DirectInputDevice8.GetCapabilities method, which returns the data in a DIDEVCAPS type.
The following code example checks whether the mouse is attached and whether it has a third axis (presumably a wheel):
'diMouse is a valid DirectInputDevice object. Dim WheelAvailable As Boolean Dim dicaps as DIDEVCAPS Call diDev.GetCapabilities(dicaps) WheelAvailable = ((dicaps.lFlags And DIDC_ATTACHED) _ And (dicaps.lAxes > 2))
Another way to check for a certain button or axis is to call DirectInputDevice8.GetObjectInfo for that object. If the call raises the error DIERR_NOTFOUND, the object is not present. The following code determines whether there is a z-axis, even if it is not the third axis:
Dim didoi As DirectInputDeviceObjectInstance On Error GoTo NOTFOUND Set didoi = diDev.GetObjectInfo(DIMOFS_Z, DIPH_BYOFFSET) On Error GoTo 0 . . . NOTFOUND: If Err.Number = DIERR_NOTFOUND Then MsgBox "No z-axis found." End If