hedgewars/uKeys.pas
changeset 6942 11f52445e8cd
parent 6917 4889c2b779b4
--- a/hedgewars/uKeys.pas	Fri Apr 27 23:09:27 2012 +0200
+++ b/hedgewars/uKeys.pas	Fri Apr 27 23:17:11 2012 +0200
@@ -46,7 +46,9 @@
 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug;
 
 var tkbd, tkbdn: TKeyboardState;
+    quitKeyCode: Byte;
     KeyNames: array [0..cKeyMaxIndex] of string[15];
+    
 
 function KeyNameToCode(name: shortstring): word;
 var code: Word;
@@ -105,17 +107,6 @@
     end;
 {$ENDIF}
 
-
-//TODO reimplement this
-// ctrl/cmd + q to close engine and frontend
-{$IFDEF DARWIN}
-    if ((tkbdn[KeyNameToCode('left_meta')] = 1) or (tkbdn[KeyNameToCode('right_meta')] = 1)) then
-{$ELSE}
-    if ((tkbdn[KeyNameToCode('left_ctrl')] = 1) or (tkbdn[KeyNameToCode('right_ctrl')] = 1)) then
-{$ENDIF}
-    begin
-        if tkbdn[KeyNameToCode('q')] = 1 then ParseCommand ('halt', true)
-    end;
 end;
 
 
@@ -131,6 +122,17 @@
 
 tkbdn[code]:= ord(KeyDown);
 
+// ctrl/cmd + q to close engine and frontend
+if(KeyDown and (code = quitKeyCode)) then
+    begin
+{$IFDEF DARWIN}
+    if ((tkbdn[KeyNameToCode('left_meta')] = 1) or (tkbdn[KeyNameToCode('right_meta')] = 1)) then
+{$ELSE}
+    if ((tkbdn[KeyNameToCode('left_ctrl')] = 1) or (tkbdn[KeyNameToCode('right_ctrl')] = 1)) then
+{$ENDIF}
+        ParseCommand('halt', true);    
+    end;
+
 if CurrentBinds[code][0] <> #0 then
     begin
     if (code > 3) and (tkbdn[code] <> 0) and not ((CurrentBinds[code] = 'put') or (CurrentBinds[code] = 'ammomenu') or (CurrentBinds[code] = '+cur_u') or (CurrentBinds[code] = '+cur_d') or (CurrentBinds[code] = '+cur_l') or (CurrentBinds[code] = '+cur_r')) then hideAmmoMenu:= true;
@@ -255,7 +257,7 @@
         end;
     end;
 
-//for i:= 0 to cKeyMaxIndex do writeln(stdout,IntToStr(i) + ': ' + KeyNames[i]);
+quitKeyCode:= KeyNameToCode('q');
 
 // get the size of keyboard array
 SDL_GetKeyState(@k);