Device Capabilities

Before you begin asking for input from a device, you may 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 machine? Such questions are answered with a call to the IDirectInputDevice::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 function.

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

Here's an example that checks whether the mouse is attached and whether it has a third axis (presumably a wheel):

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

Another way to check for a certain button or axis is to call IDirectInputDevice::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.

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