Wednesday, January 23, 2008

kbhit() equivalent in Windows MFC (VS 6.0)

Jim:

I'm just blogging this because it took me too long to find it... I needed to be able to break out of a loop by pressing a key; the example below uses the escape key. This block is within a larger loop. It samples the keyboard every 100 operations as bCount is incremented:

if(!(bCount%100)){

keyData = GetAsyncKeyState(VK_ESCAPE); //ESC KEY
if(keyData) {
break;
}
}

See the following references:

http://msdn2.microsoft.com/en-us/library/ms646293.aspx
http://msdn2.microsoft.com/en-us/library/ms645540(VS.85).aspx

0 comments: