DirectX SDK |
This topic pertains only to application development in Visual Basic. See DirectInput C/C++ Tutorials.
Now that the necessary properties have been set, the device can be acquired and data can be collected from the joystick. In the Joystick sample, the device is polled in a loop after its properties have been set. In a real-world multimedia application, polling would take place in the main game loop or rendering loop.
diDev.Acquire While DoEvents diDev.Poll Wend
The sample application does not actually retrieve immediate data each time the device is polled. To avoid unnecessary screen updates, it relies on notification, and the call to Poll is only to ensure that notifications are issued by devices that do not generate interrupts. Polling is not necessary for some game devices (such as HIDs), but it is just as efficient to make a redundant call to DirectInputDevice.Poll as it would be to check a flag for the device before calling Poll.
Notifications are handled, as usual, in the implementation of the DirectXEvent.DXCallback method. Each time this procedure is called, the application knows that some joystick event has occurred. At this point it could call DirectInputDevice.GetDeviceData to retrieve any pending axis changes or button events. However, with a game controller it would be more usual to retrieve the state of the entire device, so the sample uses DirectInputDevice.GetDeviceStateJoystick.
Dim js As DIJOYSTATE diDev.GetDeviceStateJoystick js
The values in the DIJOYSTATE type now tell the application everything it needs to know about the state of the device objects. Since it knows from Step 2: Get Joystick Capabilities what buttons, axes, and point-of-view controllers are actually present, it also knows which members of the type to ignore.