Programming Tips and Tools

This topic covers the following specialized programming tips.

Designing for Previous Versions of DirectInput

In the DirectInput8Create, IDirectInput8::Initialize, IDirectInputDevice8::Initialize, and IDirectInputEffect::Initialize methods, you are required to pass the DirectInput version number. This parameter specifies which version of DirectX the DirectInput subsystem should emulate.

Applications designed for the latest version of DirectInput should pass the value DIRECTINPUT_VERSION as defined in Dinput.h.

Applications designed to run under previous versions should pass a value corresponding to the version of DirectInput for which they were designed, with the main version number in the high-order byte. For example, an application designed to run on DirectInput 3.0 should pass a value of 0x0300.

If you define DIRECTINPUT_VERSION as 0x0300 before including the Dinput.h header file, the header file generates structure definitions compatible with DirectInput 3.0.

If you do not define DIRECTINPUT_VERSION before including the Dinput.h header file, the header file generates structure definitions compatible with the current version of DirectInput. However, the DirectX 3-compatible structures are available under the same names with "_DX3" appended. For example, the DirectX 3-compatible DIDEVCAPS structure is called DIDEVCAPS_DX3.

You must also use the appropriate versions of the DirectInput and DirectInputDevice interfaces. For versions of DirectX prior to DirectX 7.0, you must use IDirectInput and either IDirectInputDevice or IDirectInputDevice2 (the latter is available for DirectX 5.0 or later.)

Preventing Response Delays During Debugging

When using the keyboard or mouse with DirectInput under Microsoft Windows 2000, you might notice short delays in response when you step through code during a debugging session. This behavior occurs only in debug mode, so it is not seen by your application's end users. However, this behavior can be eliminated in debug mode as well by adding the emulation value to the following registry key.

HKEY_LOCAL_MACHINE
    SOFTWARE
        Microsoft
            DirectInput
Name Type Data
Emulation DWORD 0x08 (for the keyboard)

0x10 (for the mouse)

0x18 (for both)

You can also switch to use emulation from the DirectX control panel by following these steps.

  1. Open the Windows control panel
  2. Open the DirectX control panel. Note that if you are using Microsoft Windows XP, you might need to click Switch to Classic View to see the DirectX icon.
  3. Select the DirectInput tab.
  4. In the Debug Input Device Emulation section, you can check the Emulate Keyboard and Emulate Mouse boxes.

Without changing how DirectInput returns data, this value invokes an emulation mode that is not susceptible to those delays. These settings are global and affect all DirectInput clients. Performance only improves when using the debug binaries and only for applications that employ foreground exclusive device access. Some features, such as masking the Windows keys, are not available when devices are emulated so emulation is recommended only for debugging.

Note     If you are using earlier versions of DirectX, you must do a debug software development kit (SDK) install in order to get the correct debug DLL onto your computer.

Avoiding Duplicate Registry Keys

For every application that uses DirectInput 8.0 or later versions, DirectInput creates a key in the following registry.

HKEY_CURRENT_USER
	SOFTWARE
		Microsoft
			DirectInput

This allows the independent hardware vendors (IHVs) to turn off their own device mapping for certain applications. During debugging, however, each build will generate a new key which contains a time stamp and the file size. To avoid generating multiple keys in the registry, use the binary value, AppIdFlag.

The following table lists the possible values for AppIdFlag.

1 The time stamp is ignored when generating the key.
2 The file size is ignored when generating the key.
3 Both the time stamp and file size are ignored when generating the key.

If AppIdFlag is set to 3, all builds of applications with the same file name will use the same key.

Note    The AppIdFlag value should only be set on test computers to avoid the possibility of two applications that ship with the same file name interfering with each other's input control mappings.