Sign in to follow this  

having trouble with key states

Recommended Posts

Moving you to our For Beginners forum.

how do you input VK with two characters for example VK_LEFT_UP or something like that.
You don't. You check input for "left" AND "up" separately and then react to both in combination if necessary. Is that enough of a hint to proceed, or do you need to see a code snippet?

Share this post

Link to post
Share on other sites
Abstract the winproc input from your input handler. Have something that contains information about key states. The winproc modifies it (with keyup and keydown) and the program reads from it when needed.

Actually, glancing at your post tags I see you're using DirectX. Why not use DirectInput?

If not then you can just write a simple class that holds keystate bools in a private array. Friend the winproc (don't taze me, bros) and then have a 'bool operator[](DWORD vkey) const;' function on the class. (Possibly you could make the class members static so you won't even need to initialize the class.) Then you can just have the winproc manage the array contents and check like so:

[source lang="cpp"]if(inputObj[VK_LEFT] && inputObj[VK_UP]) {
//do stuff

I'd really recommend DirectInput though. Edited by Khatharr

Share this post

Link to post
Share on other sites
DirectInput is deprecated, he should be using raw input for keyboard and mouse instead (works from XP onwards).

Not like it matters, the real issue here is that he needs to learn first how to detect multiple keys. This is going to be the same regardless of which API he uses. So: just keep track of all the keys as they get pressed or released. Then if you want to check for combinations just check the state of those two keys. Plain and simple.

And yeah, you'll probably need an array for that (or something similar).

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