Jump to content
  • Advertisement

Archived

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

cxi2

Direct INput problems

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

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!