Game keep focused after ALT+TAB

Quickly doing Alt+Tab when the game starts keeps the app running on the background and even detecting input, playing music and so on.

I’m using MonoGame 3.8.0.1082.

Seems that the IsActive property is not updated if you quickly switch to another app while the game is about to start.

In addition, it also happens when switichng several times while the game is running. Seems that doing it quickly make it fail sometimes.

Any idea?

Thanks

Ok, my bad. Be sure to call base.Update() before all.

I have experienced this issue before. This should be a bug in MG.

Here is the workaround I found after 7 hours! God!

    private bool isDeactivated;
    private Form gameForm = Control.FromHandle(Window.Handle) as Form;

    protected override void Update(GameTime gameTime)
    {
        if (IsActive)
        {
            if (isDeactivated)
            {
                if (gameForm.WindowState != FormWindowState.Minimized)
                {
                    ActivateCore();
                    isDeactivated = false;
                }
            }
            else
            {
                if (!isDeactivated)
                {
                    DeactivateCore();
                    isDeactivated = true;
                }
            }
        }
    }
2 Likes