43 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
45 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
44 |
46 |
45 implementation |
47 implementation |
46 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug; |
48 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug; |
47 |
49 |
48 var tkbd: array[0..cKeyMaxIndex] of boolean; |
50 const |
|
51 LSHIFT = $0200; |
|
52 RSHIFT = $0400; |
|
53 LALT = $0800; |
|
54 RALT = $1000; |
|
55 LCTRL = $2000; |
|
56 RCTRL = $4000; |
|
57 |
|
58 var tkbd: array[0..cKbdMaxIndex] of boolean; |
49 quitKeyCode: Byte; |
59 quitKeyCode: Byte; |
50 KeyNames: array [0..cKeyMaxIndex] of string[15]; |
60 KeyNames: array [0..cKeyMaxIndex] of string[15]; |
51 CurrentBinds: TBinds; |
61 CurrentBinds: TBinds; |
52 |
62 |
53 function KeyNameToCode(name: shortstring): word; |
63 function KeyNameToCode(name: shortstring; Modifier: shortstring): LongInt; |
54 var code: Word; |
64 var code: LongInt; |
55 begin |
65 begin |
56 name:= LowerCase(name); |
66 name:= LowerCase(name); |
57 code:= cKeyMaxIndex; |
67 code:= cKeyMaxIndex; |
58 while (code > 0) and (KeyNames[code] <> name) do dec(code); |
68 while (code > 0) and (KeyNames[code] <> name) do dec(code); |
|
69 |
|
70 MaskModifier(Modifier, code); |
59 KeyNameToCode:= code; |
71 KeyNameToCode:= code; |
|
72 end; |
|
73 |
|
74 procedure MaskModifier(var code: LongInt; Modifier: LongWord); |
|
75 begin |
|
76 if(Modifier and KMOD_LSHIFT) <> 0 then code:= code or LSHIFT; |
|
77 if(Modifier and KMOD_RSHIFT) <> 0 then code:= code or LSHIFT; |
|
78 if(Modifier and KMOD_LALT) <> 0 then code:= code or LALT; |
|
79 if(Modifier and KMOD_RALT) <> 0 then code:= code or LALT; |
|
80 if(Modifier and KMOD_LCTRL) <> 0 then code:= code or LCTRL; |
|
81 if(Modifier and KMOD_RCTRL) <> 0 then code:= code or LCTRL; |
|
82 end; |
|
83 |
|
84 procedure MaskModifier(Modifier: shortstring; var code: LongInt); |
|
85 var mod_ : shortstring; |
|
86 ModifierCount, i: LongInt; |
|
87 begin |
|
88 if Modifier = '' then exit; |
|
89 ModifierCount:= 0; |
|
90 |
|
91 for i:= 1 to Length(Modifier) do |
|
92 if(Modifier[i] = ':') then inc(ModifierCount); |
|
93 |
|
94 SplitByChar(Modifier, mod_, ':');//remove the first mod: part |
|
95 Modifier:= mod_; |
|
96 for i:= 0 to ModifierCount do |
|
97 begin |
|
98 mod_:= ''; |
|
99 SplitByChar(Modifier, mod_, ':'); |
|
100 if (Modifier = 'lshift') then code:= code or LSHIFT; |
|
101 if (Modifier = 'rshift') then code:= code or RSHIFT; |
|
102 if (Modifier = 'lalt') then code:= code or LALT; |
|
103 if (Modifier = 'ralt') then code:= code or RALT; |
|
104 if (Modifier = 'lctrl') or (mod_ = 'lmeta') then code:= code or LCTRL; |
|
105 if (Modifier = 'rctrl') or (mod_ = 'rmeta') then code:= code or RCTRL; |
|
106 Modifier:= mod_; |
|
107 end; |
60 end; |
108 end; |
61 |
109 |
62 procedure ProcessKey(code: LongInt; KeyDown: boolean); |
110 procedure ProcessKey(code: LongInt; KeyDown: boolean); |
63 var |
111 var |
64 Trusted: boolean; |
112 Trusted: boolean; |
65 s : string; |
113 s : string; |
66 begin |
114 begin |
67 |
|
68 if not(tkbd[code] xor KeyDown) then exit; |
115 if not(tkbd[code] xor KeyDown) then exit; |
69 tkbd[code]:= KeyDown; |
116 tkbd[code]:= KeyDown; |
70 |
|
71 |
117 |
72 hideAmmoMenu:= false; |
118 hideAmmoMenu:= false; |
73 Trusted:= (CurrentTeam <> nil) |
119 Trusted:= (CurrentTeam <> nil) |
74 and (not CurrentTeam^.ExtDriven) |
120 and (not CurrentTeam^.ExtDriven) |
75 and (CurrentHedgehog^.BotLevel = 0); |
121 and (CurrentHedgehog^.BotLevel = 0); |
76 |
|
77 |
|
78 |
122 |
79 // ctrl/cmd + q to close engine and frontend |
123 // ctrl/cmd + q to close engine and frontend |
80 if(KeyDown and (code = quitKeyCode)) then |
124 if(KeyDown and (code = quitKeyCode)) then |
81 begin |
125 begin |
82 {$IFDEF DARWIN} |
126 {$IFDEF DARWIN} |