Share via


Device Data Formats

If you are not using Action Mapping, setting the data format for a device is an essential step before you can acquire and begin using the device. This is true even if you do not intend to retrieve immediate (state) data from the device. DirectInput uses the data format in many methods to identify particular device objects.

The IDirectInputDevice8::SetDataFormat method tells DirectInput what device objects will be used and how the data will be arranged.

The examples in the reference for the DIDATAFORMAT and DIOBJECTDATAFORMAT structures show how to set up custom data formats for nonstandard devices. Fortunately, this step is not necessary for the joystick, keyboard, and mouse. DirectInput provides five global variables, c_dfDIJoystick, c_dfDIJoystick2, c_dfDIKeyboard, c_dfDIMouse, and c_dfDIMouse2, which can be passed in to IDirectInputDevice8::SetDataFormat to create a standard data format for these devices.

In the following code example, lpdiMouse is an initialized pointer to a DirectInputDevice object:

lpdiMouse->SetDataFormat(&c_dfDIMouse); 

Note

You cannot change the dwFlags member in the predefined DIDATAFORMAT global variables (for example, to change the property of an axis), because they are const variables. To change properties, use the IDirectInputDevice8::SetProperty method after setting the data format, but before acquiring the device.