Microsoft DirectX 8.1 (Visual Basic) |
Presuming that you have found a suitable force-feedback device, the DirectInputDevice8 object created in the last step in order to check capabilities can be left in place. It requires some further normal initialization, as covered in Tutorial 3: Using the Joystick: setting the data format and cooperative level, and setting the range properties for input. Note that the cooperative level must include DISCL_EXCLUSIVE. Although an actual application probably does not require background access to the device, the DISCL_BACKGROUND flag makes debugging easier because you will not lose acquisition when you switch to the code window.
Call didev.SetCommonDataFormat(DIFORMAT_JOYSTICK2) Call didev.SetCooperativeLevel(Me.hWnd, _ DISCL_BACKGROUND Or DISCL_EXCLUSIVE) ' Set range properties...
For force feedback, it is often good practice to disable the autocenter property of the device, so that the default spring action will not interfere with effects you create. This is done by sending a DIPROPLONG type through the DirectInputDevice8.SetProperty method, setting the DIPROP_AUTOCENTER property to 0.
Dim prop As DIPROPLONG prop.lData = 0 prop.lHow = DIPH_DEVICE prop.lObj = 0 Call didev.SetProperty("DIPROP_AUTOCENTER", prop)
Once you have configured the device as desired, it can be acquired.
didev.Acquire
Now that you have a force-feedback device ready, you need to create an effect to use with it. This is covered in Step 3: Creating an Effect.