Microsoft DirectX 8.1 (Visual Basic)

Step 3: Setting Joystick Properties

Property changes are made through the DirectInputDevice8.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.

Properties are set using different types for different properties. For an axis value, use the DIPROPRANGE type. This property type structure is then applied by calling SetProperty.

Dim DiProp_Range As DIPROPRANGE
 
With DiProp_Range
    .lHow = DIPH_DEVICE
    .lMin = 0
    .lMax = 10000
End With
diDev.SetProperty "DIPROP_RANGE", DiProp_Range

The DIPH_DEVICE flag is used to indicate that the property applies to all axes on the device. The Joystick Sample also sets the dead zone and saturation zones for the joystick. In this case, it is not desirable to set these values for other axes such as a throttle or rudder. The lHow member of the property type is set to indicate 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. In this case, the DIPROPLONG type is used to send values of type Long through SetProperty. The following sample code demonstrates this for the dead zone property.

Dim DiProp_Dead As DIPROPLONG
 
With DiProp_Dead
    .lData = 1000
    .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. Because 1000 is one-tenth of 10,000, it specifies that one-tenth of the range of travel of the x-axis and y-axis, balanced at the center, will be reported as still being in the center (in this case, a value of 5000).

Note  Dead zone and saturation values are always calculated in units of 10,000, regardless of the actual 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 top and bottom 5 percent of the raw values returned by the joystick is reported as the minimum or maximum range value set for the device (in this case, 0 or 10,000).

You are now ready to get data from the device in Step 4: Retrieving Immediate Data from the Joystick.