Archived

This topic is now archived and is closed to further replies.

GetAsyncKeyState() and buffers!!!!!!!!!

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

My program was acting funny a while ago. Lots of times, i would run it, and it would immediately close. Then, i would run it again not 5 seconds later, and it would work! then, i wanted to run the loop: while(!GetAsyncKeyState(VK_RETURN)) { } with stuff in there, of course, but the loop would automatically exit. (tested this by incrementing a counter and sending to data file) then, i did this: while(GetAsyncKeyState(VK_RETURN)); while(!GetAsyncKeyState(VK_RETURN)) { } and my program works fine now. i figgered out what is happening, but not how to fix it. there is apparently a buffer of keys that have been pressed somewhere in windows. there was apparently some extra VK_RETURNs in that buffer, and they were causing the GetAsyncKeyState() thingy to return true, making the loop not ever run. i assume this is happening for my VK_ESCAPE test that exits my program. i need a way to clear the buffer that GetAsyncKeyState() reads from. CAN ANYONE HELP??? MadProgrammer

Share this post


Link to post
Share on other sites
You could try,

flush(stdin);

which should empty the input buffer, but whether this is the same buffer which windows uses for GetAsyncKeyState I have no idea. Hope this helps,

BloatWare

Share this post


Link to post
Share on other sites
...It''s a case RTFM, or RTFMSDN...

GetAsyncKeyState is _unbuffered_ and returns the current state of the key with a little history information.
It does _not_ return a boolean true/false style value as the code tries to use.

MSB = Key currently down
LSB = Key _has_been_down_ since last call to function


Jans.

Share this post


Link to post
Share on other sites