diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index 353b8247..e2285968 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -677,12 +677,40 @@ static void CaptureMouse(bool pressed) { GFX_CaptureMouse(); } +#if defined (WIN32) +STICKYKEYS stick_keys = {sizeof(STICKYKEYS), 0}; +void sticky_keys(bool restore){ + static bool inited = false; + if (!inited){ + inited = true; + SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(STICKYKEYS), &stick_keys, 0); + } + if (restore) { + SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(STICKYKEYS), &stick_keys, 0); + return; + } + //Get current sticky keys layout: + STICKYKEYS s = {sizeof(STICKYKEYS), 0}; + SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(STICKYKEYS), &s, 0); + if ( !(s.dwFlags & SKF_STICKYKEYSON)) { //Not on already + s.dwFlags &= ~SKF_HOTKEYACTIVE; + SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(STICKYKEYS), &s, 0); + } +} +#endif + void GFX_SwitchFullScreen(void) { sdl.desktop.fullscreen=!sdl.desktop.fullscreen; if (sdl.desktop.fullscreen) { if (!sdl.mouse.locked) GFX_CaptureMouse(); +#if defined (WIN32) + sticky_keys(false); //disable sticky keys in fullscreen mode +#endif } else { if (sdl.mouse.locked) GFX_CaptureMouse(); +#if defined (WIN32) + sticky_keys(true); //restore sticky keys to default state in windowed mode. +#endif } GFX_ResetScreen(); } @@ -1693,7 +1721,6 @@ static void erasemapperfile() { } - //extern void UI_Init(void); int main(int argc, char* argv[]) { try { @@ -1711,7 +1738,7 @@ int main(int argc, char* argv[]) { if(control->cmdline->FindExist("-resetconf")) eraseconfigfile(); if(control->cmdline->FindExist("-erasemapper")) erasemapperfile(); if(control->cmdline->FindExist("-resetmapper")) erasemapperfile(); - + /* Can't disable the console with debugger enabled */ #if defined(WIN32) && !(C_DEBUG) if (control->cmdline->FindExist("-noconsole")) { @@ -1901,6 +1928,7 @@ int main(int argc, char* argv[]) { control->StartUp(); /* Shutdown everything */ } catch (char * error) { + sticky_keys(true); GFX_ShowMsg("Exit to error: %s",error); fflush(NULL); if(sdl.wait_on_error) { @@ -1919,11 +1947,17 @@ int main(int argc, char* argv[]) { ;//nothing pressed killswitch } catch(...){ +#if defined (WIN32) + sticky_keys(true); +#endif //Force visible mouse to end user. Somehow this sometimes doesn't happen SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_ShowCursor(SDL_ENABLE); throw;//dunno what happened. rethrow for sdl to catch } +#if defined (WIN32) + sticky_keys(true); //Might not be needed if the shutdown function switches to windowed mode, but it doesn't hurt +#endif //Force visible mouse to end user. Somehow this sometimes doesn't happen SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_ShowCursor(SDL_ENABLE);