Contrast Development Contrast Development - 26 days ago 14
C++ Question

Keystate Inverter not working

I'm coding an ALT + ENTER SDL Window minimiser/maximiser, however even though I've set an SDL Delay before the varibale

SMax
is changed, the window only minimises for a second before going back to It's original state. How do I make the minimisation/maximisation permanent until ALT + ENTER is pressed again?

if (keyState[SDL_SCANCODE_LALT] && keyState[SDL_SCANCODE_RETURN] && SMax)
{
SDL_SetWindowFullscreen(window, 0);
SDL_SetWindowSize(window, 600, 400);
SDL_RenderPresent(renderTarget);
w = 600;
h = 400;
SDL_Delay(1000);
SMax = false;
}

if (keyState[SDL_SCANCODE_LALT] && keyState[SDL_SCANCODE_RETURN] && !SMax)
{
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_RenderPresent(renderTarget);
SDL_Delay(1000);
SMax = true;
}

Answer

keyState doesn't get updated until the next call to SDL_PumpEvents, whether you put the program to sleep or not. You need to completely skip the second test until the next frame; an else will be enough.

Comments