Jump to content
  • Advertisement
Sign in to follow this  
Xargo

DirectInput, ideal way to retrieve input?

This topic is 4080 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

Good day I've been reading quite some tutorials now, and they all seem to put the Poll() method of the input device in a loop. But in one article I read this: "As I mentioned before, there are better ways of relating keyboard and mouse keys and movement to actions in the game. (...) We are also going to fix that in the next article." - Coding4Fun Unfortunately he doesn't seem to get to it in that next article, neither in the few following articles. (The tutorial series have not been finished though.) It's a pity he didn't explain it yet, because I'm really wondering what's a better way to retrieve the input device its information apart from just putting the Poll() method in a rendering loop. I've also got a second question regarding the input handling. Because the render loop is triggered several times in a second, it often happens that one mouseclick or buttonpress on your keyboard gets registered twice, thus messing up the application. Eg. when you press shoot once, you shoot several times in a row. I know this is a common noob problem, and I know several ways to solve it. But I'd like to know the best way from you guys. :-) Thanks Xargo

Share this post


Link to post
Share on other sites
Advertisement
The best way to check for keyboard and mouse input is by catching windows messages such as KEY_UP, KEY_DOWN, etc. DirectInput is a layer on top of windows messages. Honestly, the only think I would use DirectInput for myself are legacy controllers. (Non xbox 360 Controllers).

Use a buffer of chars that store the current state of a key. When KEY_DOWN sends a message you can toggle that bit on. When KEY_UP sends a message, set the bit off.

Personally, I have been trying to avoid the use of DirectInput. The approach XInput takes is much easier to setup and manage. However, you are limited to 360 devices.

I have a short article on setting up XInput on my blog. It is a very simple and easy method to use.

jeremycafe.com/2007/04/xinput.html

Share this post


Link to post
Share on other sites
I'd second XInput. DirectInput is overly obtuse (It has to be, since it supports everything from 2 button digital pads, all the way up to full flight-sim gear.)

Even ignoring that, the standardization of XInput Device layout is huge. Using XInput, you know exactly which physical button corresponds to which logical button. In DirectInput this is not the case, logical button 1 might be the 6 o'clock face button on one pad, and the 3 o'clock button on another, or 9 o'clock, or the left shoulder button... There's absolutely no standardization, particularly across different manufacturers.

Basically, for DirectInput, you have to impliment an entire control-mapping scheme for it to be usefull. Otherwise you limit your available options to the exact make and model of the controller you used as the baseline input device. If any other pad works out (and granted there are likely at least *some* that share that layout) its really little more than a happy coincidence.

Share this post


Link to post
Share on other sites
Well, I think I'll just stick to the standard windows events then. I'm in no need to acquire XBOX controller input, neither game controller pads or so. The keyboard and mouse is enough for me at the moment. :-)

I'll check out the XInput though, 'cause it seems quite interesting.

Thanks for the answers. :-)

Share this post


Link to post
Share on other sites
Microsoft says, use WM_INPUT. Easier, faster, needs no setting up (well, it needs a buffer to store pressed keys, but nothing else).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!