KeyBindToName: Return HW's internal key name if SDL yields no name
authorWuzzy <Wuzzy2@mail.ru>
Mon, 20 Jul 2020 18:13:48 +0200
changeset 15754 684838d5fb08
parent 15753 26247a74d823
child 15755 ed45bda6f196
KeyBindToName: Return HW's internal key name if SDL yields no name
hedgewars/uInputHandler.pas
--- a/hedgewars/uInputHandler.pas	Sun Jul 19 23:28:45 2020 +0200
+++ b/hedgewars/uInputHandler.pas	Mon Jul 20 18:13:48 2020 +0200
@@ -121,8 +121,6 @@
 
 // Takes a control name (e.g. 'quit') and returns the corresponding
 // human-readable key name from SDL.
-// FIXME: Does not work 100% for all keys yet, but at least it no
-//        longer hardcodes any key name.
 // TODO: Localize
 function KeyBindToName(bind: shortstring): shortstring;
 var code: LongInt;
@@ -141,8 +139,14 @@
             KeyBindToName:= name
         else
             begin
-            WriteLnToConsole('Error: KeyBindToName('+bind+') failed to find SDL key name!');
-            KeyBindToName:= trmsg[sidUnknownKey];
+            if KeyNames[code] <> '' then
+                // Return Hedgewars internal key name if SDL key name is empty
+                KeyBindToName:= KeyNames[code]
+            else
+                begin
+                WriteLnToConsole('Error: KeyBindToName('+bind+'): Hedgewars does not have internal key name for given bind!');
+                KeyBindToName:= trmsg[sidUnknownKey];
+                end;
             end;
         end;
 end;