[Windows] Fixes bug #1555, handle ALT+F4 on Windows
authorGabriel Jacobo <gabomdq@gmail.com>
Wed, 13 Nov 2013 11:18:37 -0300
changeset 7975 1b49b680f319
parent 7974 8af2b2344e9e
child 7976 e8f93c2ebda3
[Windows] Fixes bug #1555, handle ALT+F4 on Windows
src/video/windows/SDL_windowsevents.c
--- a/src/video/windows/SDL_windowsevents.c	Wed Nov 13 09:41:21 2013 -0300
+++ b/src/video/windows/SDL_windowsevents.c	Wed Nov 13 11:18:37 2013 -0300
@@ -535,9 +535,19 @@
     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);