Sign in to follow this  
approxime

How to detect simultaneous key pressing in win32?

Recommended Posts

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
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

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