Jump to content
  • Advertisement
Sign in to follow this  
approxime

How to detect simultaneous key pressing in win32?

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

Advertisement
use a

bool keys[255];




and in you WndProc() function every time a keypress event fire just do this


keys[ASCII_CODE] = true;



and on keyup event


keys[ASCII_CODE] = false;




When you need to check for a key, just do this


// Check for the 'a' key
if (keys['a'])
{
....
}




With this method you cant check for a 'a' or a 'A' nor shift, alt nor ctrl keys... If you need this just Private Message me and i'll send you my cInput class which handles thoses keys.

[Edited by - iliak on September 21, 2004 2:45:22 AM]

Share this post


Link to post
Share on other sites

// Check for the 'a' and 'b' keys at the same time
if (keys['a'] && keys['b'])
{
....
}



It would work fine...

Share this post


Link to post
Share on other sites
Two keys will never be pressed at "exactly" the same time. What you want to do is check the time of every event and decide on a maximum time interval between two events that you will call "simultaneous". You will probably want to use some input handler with interrupt-callback methods as opposed to a polled input handler.

Note: If you use a crusty timer like the standard windows timer you only have 33 millisecond accuracy so you're likely to get events happening at exactly the same time according to the windows clock here.

Share this post


Link to post
Share on other sites
in w32 your input is event driven, meaning since you will never press you keys at the same time you will never detect if 2 keys were pressed simultaneously

there are always a few ms between presses

so just create array as mentioned above and check if the booleans are true

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!