Microsoft DirectX 9.0

Device Capabilities

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 IDirectInputDevice8::GetCapabilities method, which returns the data in a DIDEVCAPS structure. As with other such structures in Microsoft?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. For structure details, see Dinput.h.

The following code example checks whether the mouse is attached and whether it has a third axis (presumably a wheel). Assume that lpdiMouse is a valid Microsoft DirectInput?device.

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 IDirectInputDevice8::GetObjectInfo for that object. If the call returns DIERR_OBJECTNOTFOUND, the object is not present. The following code determines whether there is a z-axis, even if it is not the third axis:


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

© 2002 Microsoft Corporation. All rights reserved.