Platform SDK: DirectX

Device Capabilities

Before you begin asking for input from a device, you need to find out something about its capabilities. Does the joystick have a point-of-view hat? Is the mouse currently attached to the user's computer?

[C++]

Such questions are answered with a call to the IDirectInputDevice7::GetCapabilities method, which returns the data in a DIDEVCAPS structure. As with other such structures in DirectX, you must initialize the dwSize member before passing this structure to the method.

Note  To optimize speed or memory usage, you can use the smaller DIDEVCAPS_DX3 structure instead.

The following code example checks whether the mouse is attached and whether it has a third axis (presumably a wheel):

//  LPDIRECTINPUTDEVICE7  lpdiMouse;  // initialized previously
 
DIDEVCAPS  DIMouseCaps; 
HRESULT    hr; 
BOOLEAN    WheelAvailable; 
 
DIMouseCaps.dwSize = sizeof(DIDEVCAPS); 
hr = lpdiMouse->GetCapabilities(&DIMouseCaps); 
WheelAvailable = ((DIMouseCaps.dwFlags & DIDC_ATTACHED) 
        && (DIMouseCaps.dwAxes > 2)); 

Another way to check for a button or axis is to call IDirectInputDevice7::GetObjectInfo for that object. If the call returns DIERR_OBJECTNOTFOUND, the object is not present. The following code example determines whether there is a z-axis, even if it is not the third axis:

DIDEVICEOBJECTINSTANCE  didoi; 
 
didoi.dwSize = sizeof(DIDEVICEOBJECTINSTANCE); 
hr = lpdiMouse->GetObjectInfo(&didoi,DIMOFS_Z, DIPH_BYOFFSET); 
WheelAvailable = SUCCEEDED(hr); 
[Visual Basic]

Such questions are answered with a call to the DirectInputDevice.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 DirectInputDevice.GetObjectInfo for that object. If the call raises error DIERR_NOTFOUND, the object is not present. The following code example 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