Skip to main content

DirectInput Samples

These are the original DirectX SDK Win32 samples for the legacy DirectInput API updated to build with Visual Studio 2012 without using the DirectX SDK.

C++ (107.5 KB)
5 Star
14,032 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • How to vibrate the joystick?
    2 Posts | Last post April 08, 2019
    • How do I know if a joystick supports vibration? And how to make it vibrate?
    • The only sample on legacy DirectInput force feedback is here
    1 Posts | Last post October 13, 2017
  • DirectInput8Create heap corruption
    5 Posts | Last post February 23, 2016
    • Greetings,
      we recently had to move away from Legacy JoyPosEx to using DirectInput when we upgraded to Win8. The game controller interface is working well except the first run after a reboot. The call to DirectInput8Create leads to a heap corruption exception in ntdll. Interestingly, MS dxdiag does exactly the same (in fact, its next run asks if DirectInput check should be ignored due to the last run's exception). Our app is Win32.
      We had noted that the legacy JoyPosEx was redirected to DirectInput, and there we were having runtime exceptions in dinput.dll, which was another reason we went to using the newer MS APIs.
      It is a very vexing problem that sorely needs a solution in a timely manner.
      Cheers & much oblidged.
    • Why do you need to use DirectInput at all? Use of DirectInput for mouse and keyboard is strongly discouraged, and use of XINPUT or the Windows.Gaming.Input API are recommended for Xbox 360 Common Controller and Xbox One Common Controller support. What HID controllers in particular are you trying to support? What version of Windows are you using in particular? Windows 8.0, Windows 8.1, Windows 8.1 Update?
    • They are standard game controllers, none are specifically Xbox. All are flight simulator controls, for example pedals and yokes from PFC ( Prevision Flight Controls) - all represent the legacy type of joystick. The mention of JoyPosEx plainly indicates mouse and keyboard are not involved here.
      Windows 8.1 Pro. Product ID 00262-50484-62971-AAOEM.
      Thank you for your reply
    • Correction, I meant JOYINFOEX as opposed to JoyPosEx.
    • Chuck,
      I got access to the flight simulator and found the PFC pedals HID:
      As expected, not XINPUT compatible (nor any of our other controls), and I thought Windows.Gaming.Input was for Win10?
  • Project "CostumFormat"
    2 Posts | Last post February 14, 2016
    • Normaly the position of the mouse should be between:
      x : 0 and screen widht
      y : 0 and screen height
      but in the current case it displays weird values which are negative.
      And if i move my mouse to e.g. the left border of the screen, even if the cursor does not change its x coord 
      anymore, it still decreases the x value, same with the right, bottom and top border, normaly there shouldnt be
      any change if the cursor hits the border, neither makes the coord on top-left corner sense , which should be 
      0/0  and not -2668/-1062  (hard to say, since i mentioned the behavior when hitting the borders)
      So can you explain this weird behavior ? For me it doesnt make sense, I just wanted to have a more efficient way
      of getting the inputs by using direct input
    • It is strongly recommended that you do not use legacy DirectInput for mouse & keyboard input. That is why this package does not have a Keyboard or Mouse DI sample in it. DirectInput for these devices is just a wrapper around the Win32 messages since Windows XP--it was pre 'direct' back in Windows 98/ME days--and the added layer of complexity just causes problems. Take a look at the implementation of the Mouse class (and Keyboard class) in the DirectX Tool Kit <>.
      Really the only time you should use DirectInput is for legacy HID joysticks and game controllers, or for custom haptic devices.
  • compile error
    2 Posts | Last post August 01, 2012
    • If I load this project into Visual C++ 2010 Express and compile I get an error:
      1>------ Build started: Project: CustomFormat, Configuration: Debug Win32 ------
      1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.Targets(518,5): error MSB8008: Specified platform toolset (v110) is not installed or invalid. Please make sure that a supported PlatformToolset value is selected.
      ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    • See the sample Description "Building with Visual Studio 2010". You need to modify the Platform Toolset setting to "v100".