In computing, DirectInput is a Microsoft API for collecting input from a computer user, via input devices such as the mouse, keyboard, joystick or other game controllers. It also provides a system for action mapping, which allows the user to assign specific actions within a game to the buttons and axes of the input devices. Additionally it handles force-feedback (input/output) devices. Microsoft introduced a new input library called XInput in DirectX 9 (December 2002) specifically for Xbox 360 controllers.
DirectInput and XInput provide benefits over normal Win32 input events:
- they enable an application to retrieve data from input devices even when the application is in the background
- they provide full support for any type of input device, as well as for force feedback
- through action mapping, applications can retrieve input data without needing to know what kind of device generated that input
While DirectInput forms a part of the DirectX library, it has not been significantly revised since DirectX 8 (2001-2002). Microsoft recommends that new applications make use of the Windows message loop for keyboard and mouse input instead of DirectInput (as indicated in the Meltdown 2005 slideshow,) and to use XInput instead of DirectInput for Xbox 360 controllers.
DirectX included DirectInput from version 1.0 (1995). It initially offered true support only for joysticks, as the mouse and keyboard modules simply provided wrappers to the standard Win32 API. DirectX version 3.0 (1996) added support for keyboards and mice; it also improved joystick support. DirectX 5.0 (1997) included greatly improved joystick support, including adding force feedback, increasing the number of buttons, changing the underlying device-driver model and incorporating a COM-based API. Mouse support also increased the number of buttons seen from four to eight. In DirectX 7.0 (1999- ), DirectInput added a long-promised feature of seeing individual mice much like individual joysticks, but the feature didn't work with the later released Windows XP, even though as of 2010[update] it works with Windows 98/Me and DirectX 9. DirectX 8.0 (2000), the last version with major changes, included action mapping and broader support for different types of devices.
While Microsoft initially intended that DirectInput would handle all inputs, it hasn't turned out this way. As of 2010[update] Microsoft doesn't recommend using DirectInput for keyboards or mice, and has started pushing the newer XInput for Xbox 360 controllers. In Windows Vista and later Windows versions, the in-built action mapping UI has been removed. 
XInput, an API for "next generation" controllers, was introduced (December 2002) with the launch of the Xbox 360, giving Xbox 360 controllers full functionality under Windows XP SP1 and up. XInput has the advantage over DirectInput of significantly easier programmability. XInput is compatible with DirectX 9 and up.
DirectInput vs XInput
Microsoft has not made any major changes to DirectInput since DirectX 8, and introduced XInput later in DirectX 9: there remains some confusion about the current status and future of the two APIs. As of 2010[update] each has features the other doesn't, and neither had major updates with DirectX 10 (2006- ).
An Xbox 360 Controller with the default Microsoft driver with DirectInput has the following limitations compared to with XInput:
- the left and right triggers will act as a single axis, not as independent analog axes
- vibration effects will not operate
- querying for headset devices will not operate
According to MSDN, "the combination of the left and right triggers in DirectInput is by design. Games have always assumed that DirectInput device axes are centered when there is no user interaction with the device. However, the Xbox 360 controller was designed to register minimum value, not center, when the triggers are not being held." MSDN proffered the "solution" of combining the triggers, setting one trigger to a positive direction and the other to a negative direction, so no user interaction is indicative to DirectInput of the "control" being at center.
The above, however, ignores the fact that many DirectInput controllers, such as gamepads with dual analog sticks and racing-wheel controller sets, already map triggers and pedals independently. In addition, many DirectInput devices also have vibration effects. At least one driver, XBCD, gives the Xbox 360 controllers the vibration support, dead zones and (optionally) independent triggers through DirectInput. This suggests that Microsoft's Xbox 360 controller driver intentionally has weaker DirectInput support, rather than due to any differences between DirectInput and XInput APIs. On the other hand, Xbox 360 controller and XInput support only very basic control of vibration motors in contrast with great palette of various effects supported by DirectInput. The XBCD driver emulates support of these DirectInput vibration effects in the driver and translates them to simple commands for each motor in the controller. This approach makes reproduction of some DirectInput effects inaccurate.
The XInput API also as of 2010[update] has limits that DirectInput does not:
- XInput supports only "next generation" controllers. This limits it basically to controllers for the Xbox 360 that also have Windows drivers. Legacy Windows controllers, joysticks and generalized force-feedback devices are not supported.
- XInput supports a maximum of four controllers at a time. This is an Xbox limit, carried over to Windows. Although as of 2010[update] few PC games require more than four controllers at once, DirectInput itself has no such limitation.
- XInput does not support keyboards, mice, or mouse-type devices. While this mirrors Microsoft's recommendation not to use DirectInput with these devices, programmers can use DirectInput with these devices.
- XInput supports maxima of 4 axes, 10 buttons, 2 triggers and 8-direction digital pad per controller, compared to DirectInput's support for 8 axes, 128 buttons, and full-range POV. (Incidentally, the number of axes, buttons and triggers XInput supports corresponds directly to the Xbox 360 controller.)
As of 2010[update] XInput is for Xbox 360 controllers, while DirectInput is for any controller.
- ↑ Meltdown 2005 slideshow (.zip)
- ↑ "Taking Advantage of High-Definition Mouse Movement". MSDN. Microsoft. http://msdn2.microsoft.com/en-us/library/bb206183.aspx. Retrieved 2009-01-25.
- ↑ DirectInput ConfigureDevices in Windows Vista
- ↑ 
- ↑ "Gamepad - Rumbler Control". Free60 Project. http://www.free60.org/wiki/Gamepad#Rumbler_Control. Retrieved 2009-01-25.
- ↑ "XINPUT_VIBRATION". Msdn.microsoft.com. http://msdn.microsoft.com/en-us/library/bb174835(VS.85).aspx. Retrieved 2009-01-25.
- ↑ "DIEFFECT". MSDN. Microsoft. http://msdn.microsoft.com/en-us/library/bb219645(VS.85).aspx. Retrieved 2009-01-25.
- ↑ "DirectInput". MSDN. Microsoft. http://msdn.microsoft.com/en-us/library/ee416842%28VS.85%29.aspx. Retrieved 2010-05-30.