Original Post
Check out this code:
// Main message loop:
while (GameSwitch == true)
{
switch (GameState)
{
case 0:
Example();
GameState = 1;
Current = 1;
break;
case 1: // pause? wait for a keypress
if(WaitForKB()){
GameState = 2;
}
break;
case 2:
//ClearSurface();
DrawTile();
GameState=3;
Current = 3;
break;
case 3:
if(WaitForKB()){
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
break;
default:
GameState = Current;
}
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
ok now heres the wait for keyboard function/:::
{
TCHAR keystate[256];
HRESULT hr;
hr = DIERR_INPUTLOST;
// If input is lost then acquire and keep trying
while( DIERR_INPUTLOST == hr )
{
// Get the input''s device state, and put the state in dims
hr = g_pKeyboard->GetDeviceState( sizeof(keystate), &keystate );
if( hr == DIERR_INPUTLOST )
{
// DirectInput is telling us that the input stream has been
// interrupted. We aren''t tracking any state between polls, so
// we don''t have any special reset that needs to be done.
// We just re-acquire and try again.
hr = g_pKeyboard->Acquire();
}
}
g_pKeyboard->Acquire();
g_pKeyboard->GetDeviceState(256, &keystate); // blah
if(keystate[DIK_RETURN] & 0x80)
{
//MessageBox(hwnd, "pressed", "alert", 1);
return true;
}
return false;
Heres the problem:
The first call to waitforkb works fine.. it loops until the user pressses the return key.
the second call however, the app quits even though I am not pressing anything. I dont know why....
any ideas??
to Code, or Not To Code