hedgewars/uInputHandler.pas
changeset 13042 29357016f374
parent 12997 f06660523198
child 13045 25a9260244f3
equal deleted inserted replaced
13041:e0d5b63f4e37 13042:29357016f374
    25 procedure initModule;
    25 procedure initModule;
    26 procedure freeModule;
    26 procedure freeModule;
    27 
    27 
    28 function  KeyNameToCode(name: shortstring): LongInt; inline;
    28 function  KeyNameToCode(name: shortstring): LongInt; inline;
    29 function  KeyNameToCode(name: shortstring; Modifier: shortstring): LongInt;
    29 function  KeyNameToCode(name: shortstring; Modifier: shortstring): LongInt;
       
    30 
       
    31 function  KeyBindToCode(bind: shortstring): LongInt;
       
    32 function  KeyBindToName(bind: shortstring): ansistring;
    30 //procedure MaskModifier(var code: LongInt; modifier: LongWord);
    33 //procedure MaskModifier(var code: LongInt; modifier: LongWord);
    31 procedure MaskModifier(Modifier: shortstring; var code: LongInt);
    34 procedure MaskModifier(Modifier: shortstring; var code: LongInt);
    32 procedure ProcessMouse(event: TSDL_MouseButtonEvent; ButtonDown: boolean);
    35 procedure ProcessMouse(event: TSDL_MouseButtonEvent; ButtonDown: boolean);
    33 //procedure ProcessMouseWheel(x, y: LongInt);
    36 //procedure ProcessMouseWheel(x, y: LongInt);
    34 procedure ProcessMouseWheel(y: LongInt);
    37 procedure ProcessMouseWheel(y: LongInt);
    89     while (code <= cKeyMaxIndex) and (KeyNames[code] <> name) do inc(code);
    92     while (code <= cKeyMaxIndex) and (KeyNames[code] <> name) do inc(code);
    90 
    93 
    91     MaskModifier(Modifier, code);
    94     MaskModifier(Modifier, code);
    92     KeyNameToCode:= code;
    95     KeyNameToCode:= code;
    93 end;
    96 end;
       
    97 
       
    98 // Takes a control name (e.g. 'quit') and returns the corresponding key code,
       
    99 // if it has been bound.
       
   100 // Returns -1 if the control has not been bound.
       
   101 function KeyBindToCode(bind: shortstring): LongInt;
       
   102 var code: LongInt;
       
   103 begin
       
   104     code:= 0;
       
   105     while (code <= cKeyMaxIndex) and (CurrentBinds[code] <> bind) do inc(code);
       
   106     if code > cKeyMaxIndex then
       
   107         // Return error
       
   108         KeyBindToCode:= -1
       
   109     else
       
   110         KeyBindToCode:= code;
       
   111 end;
       
   112 
       
   113 // Takes a control name (e.g. 'quit') and returns the corresponding
       
   114 // human-readable key name from SDL.
       
   115 // FIXME: Does not work 100% for all keys yet, but at least it no
       
   116 //        longer hardcodes any key name.
       
   117 // TODO: Localize
       
   118 function KeyBindToName(bind: shortstring): ansistring;
       
   119 var code: LongInt;
       
   120     name: ansistring;
       
   121 begin
       
   122     code:= KeyBindToCode(bind);
       
   123     if code = -1 then
       
   124         KeyBindToName:= trmsg[sidUnknownKey]
       
   125     else
       
   126         begin
       
   127         name:= SDL_GetKeyName(SDL_GetKeyFromScancode(code));
       
   128         if (name <> '') then
       
   129             KeyBindToName:= name
       
   130         else
       
   131             begin
       
   132             WriteLnToConsole('Error: KeyBindToName('+bind+') failed to find SDL key name!');
       
   133             KeyBindToName:= trmsg[sidUnknownKey];
       
   134             end;
       
   135         end;
       
   136 end;
       
   137 
    94 (*
   138 (*
    95 procedure MaskModifier(var code: LongInt; Modifier: LongWord);
   139 procedure MaskModifier(var code: LongInt; Modifier: LongWord);
    96 begin
   140 begin
    97     if(Modifier and KMOD_LSHIFT) <> 0 then code:= code or LSHIFT;
   141     if(Modifier and KMOD_LSHIFT) <> 0 then code:= code or LSHIFT;
    98     if(Modifier and KMOD_RSHIFT) <> 0 then code:= code or LSHIFT;
   142     if(Modifier and KMOD_RSHIFT) <> 0 then code:= code or LSHIFT;