DirectInput

DirectInput is a component of DirectX that provides an interface for applications to access input devices such as keyboards, mice, joysticks, and gamepads. It offers a consistent and efficient way to handle input across a wide range of hardware.

Key Concepts

Core Interfaces

DirectInput provides several core interfaces for managing input:

IDirectInput8 Methods

Method Description
DirectInput8Create Initializes an instance of DirectInput.
EnumDevices Enumerates the input devices available on the system.
CreateDevice Creates an instance of an input device.

IDirectInputDevice8 Methods

Method Description
SetCooperativeLevel Sets the cooperative level for the device, determining how it interacts with other applications.
GetDeviceState Retrieves the current state of the device's objects (e.g., key presses, axis positions).
Acquire Acquires the device for input.
Unacquire Releases the device.
EnumEffects Enumerates the force feedback effects supported by the device.
CreateEffect Creates a force feedback effect.

Common Usage Patterns

  1. Initialization: Call DirectInput8Create to get an IDirectInput8 interface.
  2. Device Enumeration: Use EnumDevices to find available devices and create specific device instances using CreateDevice.
  3. Setting Cooperative Level: Call SetCooperativeLevel on the device interface to manage input focus.
  4. Acquiring the Device: Call Acquire before reading input.
  5. Reading Input: Periodically call GetDeviceState to read the current state of the device.
  6. Releasing the Device: Call Unacquire when input is no longer needed or the application is exiting.
Note: DirectInput is part of the legacy DirectX API. For modern Windows applications, consider using the Raw Input API or the Game Input API for improved performance and broader device support.

Related Topics