Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This topic is a guide to implementing Microsoft DirectX. For a broader overviewsee Understanding DirectInput.
This programming guide also provides the following subsections:
Creating DirectInput
The first step in any Microsoft DirectInput application is obtaining the IDirectInput8 Interface. You can do this most easily by calling the DirectInput8Create function.
You should create a single DirectInput object and not release it until the application terminates.
DirectInput Device Enumeration
DirectInput can query the system for all available input devicesdetermine whether they are connectedand return information about them. This process is called enumeration.
If your application is using only the standard keyboard or mouseor bothyou do not need to enumerate the available input devices. As explained under Creating a DirectInput Deviceyou can use predefined global variables when calling the IDirectInput8::CreateDevice method.
The following code examplewhere lpdi is a pointer to the IDirectInput8 Interface interfacecreates a keyboard device:
LPDIRECTINPUTDEVICE8 lpdiKeyboard; lpdi->CreateDevice(GUID_SysKeyboard&lpdiKeyboardNULL);
The first parameter in IDirectInput8::CreateDevice is an instance GUID that identifies the instance of the device for which the interface is to be created. Microsoft DirectInput has two predefined GUIDsGUID_SysMouse and GUID_SysKeyboardwhich represent the system mouse and keyboard. You can pass one of these identifiers into the IDirectInput8::CreateDevice method. The global variable GUID_Joystick should not be used as a parameter for IDirectInput8::CreateDevice because it is a product GUIDnot an instance GUID.
Note
If the computer has more than one mouseinput from all mice is combined to form the system device. The same is true for multiple keyboards.
DirectInput provides four other predefined GUIDs primarily for testing.
GUID_SysKeyboardEm
GUID_SysKeyboardEm2
GUID_SysMouseEm
GUID_SysMouseEm2
Passing one of these GUIDs to IDirectInput8::CreateDevice grants access to the system keyboard or mouse through an emulation layerat either level 1 or level 2. These GUIDs always represent the system mouse or keyboard. They are aliases for GUID_SysKeyboard and GUID_SysMouseso they are not enumerated by IDirectInput8::EnumDevices or IDirectInput8::EnumDevicesBySemantics unless the DIEDFL_INCLUDEALIASES flag is passed.
For devices other than the system mouse or keyboarduse the instance GUID for the device returned by IDirectInput8::EnumDevices or IDirectInput8::EnumDevicesBySemantics. The instance GUID for a device is always the same. You can allow the user to select a device from a list of those enumeratedthen save the GUID to a configuration file and use it again in later sessions.