Sign in to follow this  

What to use in place of DirectInput?

This topic is 3576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Ironic, really, I already made threads around DirectInput... I was going away from DirectInput anyway, did not work on Vista properly (which is horrid).

Could anyone tell me what the matching functions would be for elements such as 'SetCooperativeLevel', though? And is the replacing easy or am I entering a world of windows messages hell?

Share this post


Link to post
Share on other sites
Quote:
Original post by Jeroen Stout
Could anyone tell me what the matching functions would be for elements such as 'SetCooperativeLevel', though? And is the replacing easy or am I entering a world of windows messages hell?
For keyboard or mouse?
You shouldn't really need to get input if your window isn't the focus window, and you'll automatically be sent keyboard messages when your window is focused anyway.

It's pretty easy to do, but there's a lot of different ways to handle it. In my engine, I just check WM_KEYUP and WM_KEYDOWN messages and update an array of bools indicating if the key is down or not. Then I just check that array when I need to check if a key is pressed.
It's a bit more complicated than that because it supports WM_CHAR and functions like DidKeyBecomePressed() (I.e. was the key up last tick but down this tick) and so on.

Share this post


Link to post
Share on other sites

This topic is 3576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this