Skip to main content
gamedev.net
🔒 Locked

Direct INput problems

Started by cxi2 Nov 24, 2000 at 10:01 PM 1 replies 600+ views
Original Post
cxi2
cxi2
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
to Code, or Not To Code
Shannon Barber
Shannon Barber
You can''t require the use to hit a key to continue, and then exit right afterwards if they hit that key.

Change it so that esc exit''s the prog, and everything should work out.

The user will *never* be able to hit the enter key fast enough that it registers for the first loop, and is completely release before the second loop is executed.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
cxi2
cxi2
so you are saying the system is executing the loops too fast for the users actions to keep up...


i wasnt actually trying to make the program exit, i was actually trying to see if the if then statement works. so Should I slow down the process? like maybe using the sleep() function?

thanks


cxi

to Code, or Not To Code
to Code, or Not To Code

Topic Locked

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

Sign in to reply to this topic.