Window keys

Started by
5 comments, last by Undeadlnsanity 18 years, 4 months ago
Hello, I'm starting Windows programming and I'm searching how I can simply retrieve the current key pressed... Thanks for your answer!
Advertisement
What language are you using?
when you do something right, people won't be sure you've done anything at all.
First of all you need a message loop so that your program can check for keypresses.

Click on the links for tutorials on how to create a message loop and how to accept keyboard input.
Beat me to it. I'd give Undead a rating++, he deserves it.
when you do something right, people won't be sure you've done anything at all.
You can also use GetAsyncKeyState from the Windows API. You can find the details on it's use at MSDN. I suspect undeads method is the easier of the two if you're using C.
Patrick
OK, it works. I use the message loop and I copy wParam to a variable if
key down or I set it to -1 if key is up. My GetKey() function simply returns the variable.

Thanks a lot!

Is there a way to do it without using the message loop, like with
GetAsyncKeyState() for example?

n.b. I use C++
Your program always has to poll (check) for key presses using a loop, so no.

This topic is closed to new replies.

Advertisement