Commit 5b8b403e3e6cc5a9d180c632ffc01c141f461773

Gabriel Jacobo 2013-11-13T11:18:37

[Windows] Fixes bug #1555, handle ALT+F4 on Windows

diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index 6a0dd44..34fcbc6 100755
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -535,9 +535,19 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
     case WM_KEYUP:
         {
             SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam );
+            const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);
+
+            /* Detect relevant keyboard shortcuts */
+            if (keyboardState[SDL_SCANCODE_LALT] == SDL_PRESSED || keyboardState[SDL_SCANCODE_RALT] == SDL_PRESSED ) {
+	            /* ALT+F4: Close window */
+	            if (code == SDL_SCANCODE_F4) {
+		            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
+	            }
+            }
+
             if ( code != SDL_SCANCODE_UNKNOWN ) {
                 if (code == SDL_SCANCODE_PRINTSCREEN &&
-                    SDL_GetKeyboardState(NULL)[code] == SDL_RELEASED) {
+                    keyboardState[code] == SDL_RELEASED) {
                     SDL_SendKeyboardKey(SDL_PRESSED, code);
                 }
                 SDL_SendKeyboardKey(SDL_RELEASED, code);