Platform SDK: DirectX |
This topic pertains only to application development in Visual Basic. See DirectInput C/C++ Tutorials.
Property changes are made through the DirectInputDevice.SetProperty method, and must be made after the data format of the device is established, but before it is acquired.
Because different devices might return different ranges of axis values, it is a good idea to set a range that will apply to all devices. The Joystick sample requests that all axis values be within the range 0 to 10,000.
Dim DiProp_Range As DIPROPRANGE With DiProp_Range .lHow = DIPH_DEVICE ' Set for all axes .lSize = Len(DiProp_Range) .lMin = 0 .lMax = 10000 End With diDev.SetProperty "DIPROP_RANGE", DiProp_Range
Note that you must specify the length of the DIPROPRANGE type within its lSize member, because the method can handle parameters of different types, and must know how much memory to allocate. If you're used to programming in C++, you should also note that Len(DIPROPRANGE) is not valid, because it returns zero.
The Joystick sample also sets the dead zone and saturation zones for the stick. In this case, it's not desirable to set these values for other axes such as a throttle or rudder, so the lHow member of the property type is set to indicated that the property change applies to a device object identified by its offset within the data format, and the lObj member is set to that offset value.
Dim DiProp_Dead As DIPROPLONG With DiProp_Dead .lData = 1000 .lObj = DIJOFS_X .lSize = Len(DiProp_Dead) .lHow = DIPH_BYOFFSET ' Set for x-axis .lObj = DIJOFS_X diDev.SetProperty "DIPROP_DEADZONE", DiProp_Dead ' Set for y-axis .lObj = DIJOFS_Y diDev.SetProperty "DIPROP_DEADZONE", DiProp_Dead End With
The value in lData is the proportion of the range of travel, in units of 10,000, that is set up as a dead zone. The value of 1000 used in the example specifies that the middle 10 percent of the range of travel on the x-axis and y-axis will be reported as 5000, which happens to be the center of the range set in the previous step.
Note Dead zone and saturation values are always in units of 10,000, regardless of the range of values reported by the device.
The saturation zones for the device are set similarly. In this case lData is 9500, because it represents the proportion of the range of travel that lies outside the saturation zones at the extremities. In other words, the bottom and top 5 percent of the raw values returned by the stick will be reported as the minimum or maximum range value set for the device (in this case, 0 or 10,000).