PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

How to create a WaitForKeyPressed function

This is what I have tried (supposing that we have to press the left button to continue)

GDKEYLIST keyList;
GetKeyList(&keyList; );

while ( GetAsyncKeyState(keyList.vkLeft) == 0);

but it doesn't seem to be a very nice solution, because it freezes my app and I cannot even more the screen since I'm not receiving events.

Is there another way of doing that?

Thanks
You need a message pump.

This is untested, and may actually work. :) Regardless this is the general idea.

Code:

GDKEYLIST keyList;
GetKeyList(&keyList );

BOOL bRet=1;
MSG msg;

while ( GetAsyncKeyState(keyList.vkLeft) == 0 &&
((bRet=GetMessage(&msg, hWnd, 0, 0)) > 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (bRet < 1) {
//Error in message pump or my app needs to quit
return;
}


Dan East
Thanks a lot, Dan.
Oh, one side note. You'll see GetMessage's BOOL return value is not actually treated as boolean. That's Microsoft's strangeness there. It's -1 if an error occurred, 0 if WM_QUIT was received, and 1 if success.

Dan East
You can get the error returned using the GetLastError function.

And just to be correct (you might say pedantic) the return is non-zero for success.