Microsoft DirectX 8.1 (Visual Basic) |
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. Microsoft® DirectInput® uses the data format in many methods to identify particular device objects.
The DirectInputDevice8.SetCommonDataFormat and DirectInputDevice8.SetDataFormat methods tell Microsoft® DirectInput® what device objects will be used and how the data will be arranged.
For standard devices—the mouse, keyboard, and any game controller whose input data can be described in a DIJOYSTATE or DIJOYSTATE2 type—you can set the data format by calling the SetCommonDataFormat method, passing in a constant from the CONST_DICOMMONDATAFORMATS enumeration. The common data formats are adequate for most applications.
For specialized devices, you must pass a description of the data format to the SetDataFormat method. The following code example sets the data format for a device with two axes, both of which require a Long for their data, and no buttons:
Dim dx As New DirectX8 Dim di As DirectInput8 Dim did As DirectInputDevice8 Dim fD As DIDATAFORMAT Dim fDA(1) As DIOBJECTDATAFORMAT Private Sub Form_Load() Set di = dx.DirectInputCreate() Set did = di.CreateDevice("GUID_SysMouse") fDA(0).lFlags = DIDOI_POLLED fDA(0).lOfs = 0 fDA(0).lType = DIDFT_RELAXIS fDA(0).strGuid = "GUID_XAxis" fDA(1).lFlags = DIDOI_POLLED fDA(1).lOfs = 4 fDA(1).lType = DIDFT_RELAXIS fDA(1).strGuid = "GUID_YAxis" fD.dataSize = 8 fD.lFlags = DIDF_RELAXIS fD.lObjSize = 4 fD.numObjs = 2 did.SetDataFormat fD, fDA() End Sub