Search code examples
c++joystickdirectinput

USB Joystick with C++ and DirectInput


I've been trying to read data (x/y axis, pressed buttons, etc) from a usb joystick, and I've heard of DirectInput. Been searching for some long hours to find a decent example or walkthrough with little success. If anyone can share a simple tutorial, or guide me to the correct place, I'll be in your debt. Thank you

edit: Trying to achieve this goal on Windows platform


Solution

  • There are a few DirectInput samples in DirectX SDK, source code and compiled binaries. Included is Joystick sample. Older versions of SDK (look for "DirectX 9.0 SDK", years around 2004-2005) had even more samples, up to a dozen!

    Joystick Sample


    Description The Joystick sample program obtains and displays joystick data.

    Path Source: (SDK root )\Samples\C++\DirectInput\Joystick

    Executable: (SDK root )\Samples\C++\DirectInput\Bin\Joystick.exe

    User's Guide Observe how the displayed data changes when you move and twist the stick, rotate the throttle wheel, and press buttons in various combinations.

    Programming Notes The application polls the joystick for immediate data in response to a timer set inside the dialog procedure.