Skip to main content
GameDev.net gamedev.net
🔒 Locked

GetAsyncKeyState() Versus the Message Loop

Started by jtmerchant Sep 7, 2003 at 10:26 PM 1 replies 1.1k views
Original Post
jtmerchant
jtmerchant
First of all, I''d like to say I''m using C++. In the book I''m reading, a sample uses the GetAsyncKeyState() function to check the user''s keyboard input. I''m a bit confused, as I''m used to seeing a check for WM_KEYDOWN in the message loop. In the samples of the book, the author checks for a message in the message loop, if he gets one he sends it to the wndProc() function, and if no message is found, the code calls a function that does everthing that would be normally processed while the program is idle. In this particular sample, in the "idle" function, called display() (the book is based on DirectX), has the function GetAsyncKeyState() checking for the A and S keys. I''m not an advanced windows programmer, so I don''t completely know what it is. My question is: what is the difference between using GetAsyncKeyState() as compared to the message loop for checking for a key that the user presses down? Joshua Merchant
daerid
daerid
GetAsyncKeyState gets the current key state at any time, rather than waiting for input from the user. It''s a touch more accurate than waiting around for a message to be posted to the window
daerid@gmail.com
xDS4Lx
xDS4Lx
yeah but if you use GetAsyncKeyState() and yoru app is minimized it will still get the key state, so if someone is pressing the arrow key or whatever in word, your guy in your game gets moved around also. so if you use GetAsyncKeyState keep track of weather or not your app has the focus.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.