Jump to content

View more

Image of the Day

The beast has a mighty searchlight of evil! #screenshotsaturday https://t.co/bzKepOojDL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

having trouble with key states

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1 ironsam   Members   

114
Like
0Likes
Like

Posted 17 November 2012 - 01:01 PM

how do you input VK with two characters for example VK_LEFT_UP or something like that.

Edited by ironsam, 17 November 2012 - 04:59 PM.


#2 jbadams   Senior Staff   

25504
Like
2Likes
Like

Posted 17 November 2012 - 06:32 PM

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?

- Jason Astle-Adams


#3 ironsam   Members   

114
Like
0Likes
Like

Posted 17 November 2012 - 06:46 PM

i need a snippet of code

#4 Khatharr   Members   

8648
Like
0Likes
Like

Posted 19 November 2012 - 08:39 PM

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}[/source]

I'd really recommend DirectInput though.

Edited by Khatharr, 19 November 2012 - 09:07 PM.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#5 Sik_the_hedgehog   Members   

3002
Like
1Likes
Like

Posted 19 November 2012 - 09:04 PM

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).
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.