Sign in to follow this  
JohnHurt

Keyboard input

Recommended Posts

JohnHurt    334
What do you guys use for getting keyboard input? For ages I've been using GetAsyncKeyState(), is there any advantage of using say Direct Input?

Share this post


Link to post
Share on other sites
Drew_Benton    1861
Oh yes![smile] Direct Input, while a bit more complicated than Win32 API input, is far more powerful and useful. There is possibilities to get buffered input, so you can be sure you do not miss any keystrokes. Hey, nothing worse than your ship not firing in your game, right? [grin]

While Direct Input has some nice features for handling input, it is by no means the best. You will have to do some research before you can get a good working library out of it, as it seems you would have to do with ALL of DX components... Luckily I had a book that went over it, so it was ok for me.

If you are doing game programming, I would suggest Direct Input, unless what you are using has built in input - such as SDL, GLFW, Allegro, etc... I know that I can use my DI library in GLFW, for it is just an OpenGL wrapper, but It does not work in SDL and I'm sure it won't work in Allegro.

It all depends on what you are doing. If you could use some more control over input, DI is the way to go. It is well worth the extra time to learn how it works in order to have a better input system in your games. Be aware though, it's a litle tricky! I know I could not figre out how to use the mouse coordinates since they are in relative terms (change in movments) and not the actual position, so I just used the Win32 API method of getting it [lol]. I know Oluseyi has pointed out how to change this, but I can't remember where that post was.

Share this post


Link to post
Share on other sites
JohnHurt    334
Yes, buffered input seems to be a good reason. I've noticed that during occasional pauses in gameplay (for whatever reason - random hard-drive activity, email prog firing up!) i would lose some keystrokes. I already use DX to get mouse input, and it certainly seems to be the easiest of the DX modules to use (i abandoned D3D last year in favour of OGL). I'll give it a go. BTW is the buffering of input under the hood, or do you need to handle it in some way?

Share this post


Link to post
Share on other sites
Dave Hunt    4872
The buffering is handled automatically (assuming you enable buffering when you set up the device). But, with buffered input, you will (obviously) have to use a loop to extract the buffered events.

Share this post


Link to post
Share on other sites

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