DirectInput
From Wikipedia, the free encyclopedia
DirectInput is a library of objects for collecting input from the user, via input devices such the mouse, keyboard, joystick or game controllers. It also provides a system for action mapping, which allows you to assign specific actions within a game to the buttons and axis on your input devices.
While DirectInput is a part of the DirectX library it has not been significantly revised since DirectX 8. It should be noted that 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.[1]
[edit] XInput
XInput is an API for "next generation" controllers, and was introduced with the launch of the Xbox 360, allowing Xbox 360 controller to be fully functional under Windows XP SP1 and up. XInput has the advantage that it is significantly easier to program with than DirectInput.[2] XInput is compatible with DirectX 9 and up.
When using Xbox 360 Controller with the default driver with DirectInput API, there are following changes:
- The left and right trigger buttons will act as a single button, not independently
- The vibration effects will not be available
- Querying for headset devices will not be available
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's 'solution' was to combine 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.[3]
The above, however, ignores the fact that many DirectInput controllers, such as game pads with dual analog sticks and racing wheel controller sets, already map triggers and pedals independently. In addition, many DirectInput devices also have vibration effects. There is at least one driver, XBCD, that gives the Xbox 360 controllers vibration support, dead zones and (optionally) independent triggers through DirectInput. This indicates Microsoft's Xbox 360 controller driver intentionally has weaker DirectInput support, rather than due to any differences between DirectInput and XInput APIs.
The XInput API also currently has limits that DirectInput does not:
- Supports only "next generation" controllers. This limits it basically to controllers for the Xbox 360 that also have windows drivers. Legacy windows controllers are not supported.
- Maximum of four controllers at a time. This is an Xbox limit that is carried over to Windows. Although there are currently few PC games that need more than four controllers at once, this seems like an arbitrary restriction as DirectInput has no such limitation.
- Does not support keyboards, mice, or mouse-type devices. While this mirrors Microsoft's recommendation not to use DirectInput with these devices, it is possible to use DirectInput with these devices.
- Support for only 4 axes, 10 buttons, 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 and buttons XInput supports corresponds directly to the Xbox 360 controller.)