What to use in place of DirectInput?

Started by
10 comments, last by Evil Steve 16 years, 1 month ago
I was doing some reading earlier and read that Microsoft recommends not using DirectInput anymore. What am I supposed to use in it's place? The Win32 API function GetAsyncKeyState()? What happened that suddenly DirectInput isn't the preferred way to get input anymore?
Advertisement
I recently moved from direct input to raw input for both mouse and keyboard. Works very well, cant tell the difference really. You receive the WM_INPUT message after registering raw input devices. I check what went up/down or moved with that message, update my states for keys buttons and movement.
Are you referring to this family of functions?

Clicky
There you go. They work around WM_INPUT.
Thanks. I wasn't sure if you meant 'raw input' as a generic term or not, so I looked that up. ++r.
One more thing, there is an example on msdn about getting the raw mouse input where they use a #define HID_USAGE_GENERIC_MOUSE 0x02. Not sure where this comes from, maybe I missed something but it works. I extended it to use keyboard initially but i wasnt receiving keys. Then I happened across 0x06 being used for keyboard. Which I use when registering a keyboard (RegisterRawInputDevices(...)) and the key input kicked in for WM_INPUT. Killed 15-20 minutes trying to figure that out thought might be helpful.
Quote:Original post by NumberXaero
I recently moved from direct input to raw input for both mouse and keyboard. Works very well, cant tell the difference really. You receive the WM_INPUT message after registering raw input devices. I check what went up/down or moved with that message, update my states for keys buttons and movement.


That's because all DInput does is create a separate thread for processing WM_INPUT messages (On WinXP and Vista, at least). If you process WM_INPUT yourself, you get all the advantages of high-resolution mouse input without the overhead of an additional thread or the complexity of DInput. You also don't stop receiving the legacy mouse messages (WM_MOUSEMOVE and friends) which means that you can use those for GUI input if needed.

As for the keyboard I find it's best to just stick with the standard Win32 messages, or just call GetAsyncKeystate(). Or at least don't kill those messages when you register your raw input devices, so that you can use them for GUI input (raw input ignores things like caps lock and key repeats, which is annoying for entering text into edit boxes).
I think GetKeyboardState() will get the job done. I won't be needing the mouse on this one project. How do I check the 'high order bit' of my key values? The code below isn't working very well, because it's always true!

GetKeyboardState(Key);
if (Key[VK_ESCAPE]) do_something;
Try this instead.

GetKeyboardState(Key);if (Key[VK_ESCAPE] & 0x80 ) do_something;
BTW: if the input you want from the keyboard is text, use WM_CHAR instead of raw input or the Get*() functions so that you get things like key map and IME support. For "button number 102 was pressed" game control input where you want low latency, GetAsyncKeyState() or one of the other methods suggested is the way to go.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

This topic is closed to new replies.

Advertisement