Device Properties

Properties of DirectInput devices include the size of the data buffer, the range and granularity of values returned from an axis, whether axis data is relative or absolute, and the dead zone and saturation values for a joystick axis, which affect the relationship between the physical position of the stick and the reported data. Specialized devices may have other properties as well.

With one exception — the gain property of a force feedback device — properties may only be changed when the device is in an unacquired state.

Before calling the IDirectInputDevice::SetProperty or IDirectInputDevice::GetProperty methods you need to set up a property structure, which consists of a DIPROPHEADER structure and one or more elements for data. There are potentially a great variety of properties for input devices, and SetProperty must be able to work with all sorts of structures defining those properties. The purpose of the DIPROPHEADER structure is to define the size of the property structure and how the data is to be interpreted.

DirectInput includes three predefined property structures:

For SetProperty, the data members of the property structure are the values you want to set. For GetProperty, the current value is returned in these members.

Before the call to GetProperty or SetProperty, the DIPROPHEADER structure must be initialized with the following:

When getting or setting properties for a whole device, the object identifier dwObj is zero and the "how" code dwHow is DIPH_DEVICE. If you want to get or set properties for a device object (for example, a particular axis), the combination of dwObj and dwHow values identifies the object. For details, see the reference for the DIPROPHEADER structure.

After setting up the property structure, you pass the address of its header into GetProperty or SetProperty, along with an identifier for the property you want to obtain or change.

The following values are used to identify the property passed to SetProperty and GetProperty. See the reference for IDirectInputDevice::GetProperty for more information.

For more information about the last three properties, see also Interpreting Joystick Axis Data.

The following example sets the buffer size for a device so that it will hold 10 data items:

DIPROPDWORD  dipdw; 
HRESULT      hres; 
dipdw.diph.dwSize = sizeof(DIPROPDWORD); 
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); 
dipdw.diph.dwObj = 0; 
dipdw.diph.dwHow = DIPH_DEVICE; 
dipdw.dwData = 10; 
hres = lpdiDevice->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph);