Microsoft DirectX 8.1 (Visual Basic) |
This topic is a guide to implementing Microsoft® DirectInput®. It includes information on the following:
For a broader overview, see Understanding DirectInput.
For related information, see the following:
The first step in any Microsoft® DirectInput® application is creating the DirectInput8 object. Do this by using the DirectX8.DirectInputCreate method.
You should create a single DirectInput8 object and not destroy it until the application terminates.
Microsoft® DirectInput® can query the system for all available input devices, determine whether they are connected, and return information about them. This process is called enumeration.
If your application is using only the standard keyboard or mouse, or both, you do not need to enumerate the available input devices. See Creating a DirectInput Device.
For all other input devices, and for systems with multiple keyboards or mouse devices, call DirectInput8.GetDIDevices to build a collection of available devices. This method returns a DirectInputEnumDevices8 object representing the collection. Each device in the collection can be retrieved as a DirectInputDeviceInstance8 object by using the DirectInputEnumDevices8.GetItem method. The following example shows how to build a collection of game controllers and display them in a list box named lstJoysticks.
Dim diDevEnum As DirectInputEnumDevices8 Set diDevEnum = di.GetDIDevices(DI8DEVCLASS_GAMECTRL, DIEDFL_ATTACHEDONLY) Dim i As Integer For i = 1 To diDevEnum.GetCount Call lstJoysticks.AddItem(diDevEnum.GetItem(i).GetInstanceName) Next i
At the very least, you must retrieve the unique identifier for a nonstandard device from the enumeration by calling DirectInputDeviceInstance8.GetGuidInstance before you can create a DirectInputDevice8 object for that device. You might also want to enumerate devices in order to look for particular types and subtypes (by using DirectInputDeviceInstance8.GetDevType) or to populate a list box that enables the user to select a game controller.
You might even want to search for a device with particular capabilities. To do this, create a DirectInputDevice8 object for each candidate in order to examine it further by using the DirectInputDevice8.GetCapabilities method.