Microsoft DirectX 8.1 (Visual Basic) |
There are two ways to find out whether input data is available: polling and event notification.
Polling a device means regularly getting the current state of the device objects or checking the contents of the event buffer. Polling is typically used by real-time games that are never idle, but instead are constantly updating and rendering the game world.
In a Microsoft® Visual Basic® application, polling would typically be done in the Sub Main procedure.
Some joysticks and other game devices, or particular objects on them, do not generate hardware interrupts and do not return any data or signal any events until you call the DirectInputDevice8.Poll method. (This behind-the-scenes polling is not to be confused with the kind of application polling just discussed. Poll does not retrieve any data, but merely makes data available.)
To find out whether it is necessary to call Poll each time you want to retrieve data, first set the data format for the device, then call the DirectInputDevice8.GetCapabilities method and check for the DIDC_POLLEDDATAFORMAT flag in the DIDEVCAPS type.
Do not confuse the DIDC_POLLEDDATAFORMAT flag with the DIDC_POLLEDDEVICE flag. The latter is set if any object on the device requires polling. You can then find out whether this is the case for a particular object by calling the DirectInputDevice8.GetObjectInfo method to get a DirectInputDeviceObjectInstance object, and then checking for the DIDOI_POLLED flag in the valued returned by DirectInputDeviceObjectInstance.GetFlags.
The DIDC_POLLEDDEVICE flag describes the worst case for the device, not the actual situation. For example, an HID mouse with software-controllable resolution might be marked as DIDC_POLLEDDEVICE because reading the resolution information requires polling. If you want to retrieve only the standard button and axis data, polling the device under these conditions is not necessary. However, there is no harm in calling the Poll method for any input device. If the call is unnecessary, it has no effect and is very fast.
Event notification is suitable for applications such as the ScrawlB Sample that wait for input before doing anything.
To use event notification, implement DirectXEvent8 in the form or module in which you want to retrieve data. Then create an event handle by using DirectX8.CreateEvent, and pass this handle to DirectInputDevice8.SetEventNotification. Now, whenever an input event occurs on the device, the DirectXEvent8.DXCallback method is called, and in your implementation of this method you can retrieve either the device state or buffered data just as you would if you were doing so in Sub Main.