DirectInput
Encyclopedia
In computing, DirectInput is a Microsoft
Microsoft
Microsoft Corporation is an American public multinational corporation headquartered in Redmond, Washington, USA that develops, manufactures, licenses, and supports a wide range of products and services predominantly related to computing through its various product divisions...

 API for collecting input from a computer user, via input devices such as the mouse, keyboard
Computer keyboard
In computing, a keyboard is a typewriter-style keyboard, which uses an arrangement of buttons or keys, to act as mechanical levers or electronic switches...

, joystick
Joystick
A joystick is an input device consisting of a stick that pivots on a base and reports its angle or direction to the device it is controlling. Joysticks, also known as 'control columns', are the principal control in the cockpit of many civilian and military aircraft, either as a center stick or...

 or other game controller
Game controller
A game controller is a device used with games or entertainment systems used to control a playable character or object, or otherwise provide input in a computer game. A controller is typically connected to a game console or computer by means of a wire, cord or nowadays, by means of wireless connection...

s. 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 the Xbox 360 controller
Xbox 360 Controller
The Xbox 360 Controller is the primary controller for Microsoft's Xbox 360 console and was introduced at E3 2005. The Xbox 360 controller comes in both wired and wireless versions. Original Xbox controllers are not compatible with the Xbox 360...

.

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
DirectX
Microsoft DirectX is a collection of application programming interfaces for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with Direct, such as Direct3D, DirectDraw, DirectMusic, DirectPlay,...

 library, it has not been significantly revised since DirectX 8 (2001–2002). Microsoft recommends that new applications make use of the Windows message loop
Message loop in Microsoft Windows
Microsoft Windows programs are event-based. They act upon messages that the operating system posts to the main thread of the application. These messages are received from the message queue by the application by repeatedly calling the GetMessage function in a section of code called the "event...

 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.

History

DirectX included DirectInput from version 1.0 (1995). It initially offered true support only for joysticks, as the mouse and keyboard modules simply provided wrapper
Driver wrapper
A driver wrapper is software that functions as an adapter between an operating system and a driver, such as a device driver, that was not designed for that operating system. It can enable the use of devices for which no drivers for the particular operating system are available...

s to the standard Win32 API
Windows API
The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces available in the Microsoft Windows operating systems. It was formerly called the Win32 API; however, the name "Windows API" more accurately reflects its roots in 16-bit Windows and its support on...

. 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
Component Object Model
Component Object Model is a binary-interface standard for software componentry introduced by Microsoft in 1993. It is used to enable interprocess communication and dynamic object creation in a large range of programming languages...

-based API
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...

. 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
Windows XP
Windows XP is an operating system produced by Microsoft for use on personal computers, including home and business desktops, laptops and media centers. First released to computer manufacturers on August 24, 2001, it is the second most popular version of Windows, based on installed user base...

, even though 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. Microsoft doesn't recommend using DirectInput for keyboards or mice, and has started pushing the newer XInput for Xbox 360 controllers. In Windows Vista
Windows Vista
Windows Vista is an operating system released in several variations developed by Microsoft for use on personal computers, including home and business desktops, laptops, tablet PCs, and media center PCs...

, Windows 7 and later Windows versions, the in-built action mapping UI has been removed.

XInput

XInput, an API for "next generation" controllers, was introduced in December 2005 alongside the launch of the Xbox 360
Xbox 360
The Xbox 360 is the second video game console produced by Microsoft and the successor to the Xbox. The Xbox 360 competes with Sony's PlayStation 3 and Nintendo's Wii as part of the seventh generation of video game consoles...

. This instruction set provided full support for Xbox 360 controllers in Windows XP
Windows XP
Windows XP is an operating system produced by Microsoft for use on personal computers, including home and business desktops, laptops and media centers. First released to computer manufacturers on August 24, 2001, it is the second most popular version of Windows, based on installed user base...

 SP1 and subsequent operating systems, and is described by Microsoft as being easier to program for and requiring less setup than DirectInput. XInput is compatible with DirectX
DirectX
Microsoft DirectX is a collection of application programming interfaces for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with Direct, such as Direct3D, DirectDraw, DirectMusic, DirectPlay,...

 version 9 and later.

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. each has unique features not present in the other, and neither had major updates since the release of DirectX 9 (2002).

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 representing the signed difference between the triggers, 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 gamepad
Gamepad
A gamepad , is a type of game controller held in two hands, where the digits are used to provide input. Gamepads generally feature a set of action buttons handled with the right thumb and a direction controller handled with the left...

s 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
XBCD
XBCD is a driver that allows owners of an Xbox controller to use it on a Windows computer. The controller itself is a USB device with an extra wire...

, 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 XInput API also 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
    Microsoft Windows
    Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

    . Although 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 maximum 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.)


XInput is for Xbox 360 controllers, while DirectInput is for any controller.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK