|
-
Jun 19th, 2003, 12:58 AM
#1
Thread Starter
Fanatic Member
Search if Key is pressed [RESOLVED]
Hi!
I was trying to make an interactive program, and wanted to put this in it:
Code:
do stuff...
if(left button is pressed)
{
change a certain value
}
keep doing stuff
Of course, this is only pseudo-code.
I know about cin>> but the problem is i don't want the program to stop when i check for input.
any ideas?? Thanks
Last edited by sql_lall; Jun 21st, 2003 at 05:33 AM.
sql_lall 
-
Jun 19th, 2003, 05:05 PM
#2
Frenzied Member
Use the GetAsyncKeyState() api, the virtual keycode is the only argument. It returns>0 if the key has been pressed at any time since you last called GetAsyncKeyState.
You can put the call to GetAsyncKeyState in a function that you access via SetTimer, or inside the code block that reads the keyboard.
Since people can't push keys faster than 6-8 times per second a timer with a wait of 120ms is adequate. The automatic repeat on keys is usually 6 keys/sec
-
Jun 19th, 2003, 05:27 PM
#3
Frenzied Member
just note I experienced compatablitity problems with this and windows 98....works perfectly in XP though
-
Jun 19th, 2003, 09:40 PM
#4
Also the GetAsyncKeyState() doesn't care if your application had input focus when the key was pressed or not.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Jun 20th, 2003, 04:43 AM
#5
Thread Starter
Fanatic Member
Thanks
Thanks for the help.
Just wondering what kind of things i must #include at the start to be able to use it.
sql_lall 
-
Jun 20th, 2003, 06:12 AM
#6
<windows.h>
Notw also that it is non-portable.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|