Jump to content
  • Advertisement
Sign in to follow this  
g0nzo

problems with input when app loses focus

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

Hi. When my app is in window mode and loses focus it should disable its input (i use dinput) and redraw last frame so the window won't be overdrawn. In my DrawFrame() function i only draw a grid so i can see where the camera is looking. I also print out mouse coordinates, position of my camera and lookat vector. Now it works like this: when my app loses focus it redraws last frame and everything seems to be ok, but when i move a cursor over the window (without activating it) things that i draw in DrawFrame() function disappear (it looks like very quick zoom out, lines quickly get smaller and disapear) but the text still stays and it shows that the camera didn't move (i'm not updating the camera when app is inactive). When i click on my app and activate it, my mouse coordinates change to something about -8000000 or 17000000 etc. but the camera looks more or less where it was before deactivating. Here's my main loop:
        do
        {
            app->CheckMessages();

            if (app->m_bActive)
            {                
                camera->Update();            
            }

	    input->Update();
	    timer->Update();

            app->DrawFrame();   
            
            text->Color(1.0f,1.0f,1.0f);  
            text->Print(10, 50, "Camera position -> %.1f %.1f %.1f",camera->GetPos().x, camera->GetPos().y, camera->GetPos().z);
            text->Print(10, 75, "Camera looks at -> %.1f %.1f %.1f",camera->GetLookAt().x, camera->GetLookAt().y, camera->GetLookAt().z);            
            text->Print(10, 100, "MouseX: %d", input->MouseX());
            text->Print(10, 125, "MouseY: %d", input->MouseY());
            
            app->EndFrame();

            // Exit if ESCAPE was pressed            
            if (input->KeyDown(DIK_ESCAPE))
            {
        	    // exit
            }
            
            if (input->KeyOnce(DIK_F1))
            {
				// toggle fullscreen
            }   

	}while (!app->m_bToggleFullscreen && !app->m_bExit);



I'm not sure where input->Update() should be, because it's created using DISCL_FOREGROUND so it shouldn't get any input while the app is inactive anyway and if i put it inside if (app->m_bActive) {} it works exactly the same. [Edited by - g0nzo on March 10, 2005 2:04:29 PM]

Share this post


Link to post
Share on other sites
Advertisement
When DirectInput applications lose focus, you have to create the DInput device again after you've regained focus for the window. It's a known problem in a few games.
Here's what I do when my application gains focus again:

if( Message == "GainFocus" )
{
m_Active = true;

// Re-acquire devices
m_pKeyboard->Acquire();
m_pMouse->Acquire();
return true;
}

Share this post


Link to post
Share on other sites
Thanks for your answer.

When i added Acquire it was crashing during start up, when WM_ACTIVE was passed for the first time. I tried to Unacquire it but before calling Acquire but it didn't help.

However i changed something else and it works now :)

When my app was inactive i was drawing the same frame all the time instead of just putting the buffer on the screen. Now if app is inactive i don't draw the whole frame every loop, i just call SwapBuffers() and it works :)

However now, when activating the window by clicking on it the camera is moved in the direction of the point which was clicked.

EDIT: fixed that. I changed 1 case:


case WA_ACTIVE:
case WA_CLICKACTIVE:
app->m_bActive = true;

input->Free();
input->Init();
break;



into 2 cases:


case WA_ACTIVE:
app->m_bActive = true;
break;
case WA_CLICKACTIVE:
app->m_bActive = true;

input->Free();
input->Init();
break;



and now everything works:)



[Edited by - g0nzo on March 10, 2005 4:07:41 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!