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 var tkbd: array[0..cKbdMaxIndex] of boolean; |
49 quitKeyCode: Byte; |
51 quitKeyCode: Byte; |
50 KeyNames: array [0..cKeyMaxIndex] of string[15]; |
52 KeyNames: array [0..cKeyMaxIndex] of string[15]; |
51 CurrentBinds: TBinds; |
53 CurrentBinds: TBinds; |
52 |
54 |
53 function KeyNameToCode(name: shortstring): word; |
55 function KeyNameToCode(name: shortstring; Modifier: shortstring): LongInt; |
54 var code: Word; |
56 var code: LongInt; |
55 begin |
57 begin |
56 name:= LowerCase(name); |
58 name:= LowerCase(name); |
57 code:= cKeyMaxIndex; |
59 code:= cKeyMaxIndex; |
58 while (code > 0) and (KeyNames[code] <> name) do dec(code); |
60 while (code > 0) and (KeyNames[code] <> name) do dec(code); |
|
61 |
|
62 |
|
63 MaskModifier(Modifier, code); |
|
64 WriteLnToConsole(inttostr(code)); |
|
65 |
59 KeyNameToCode:= code; |
66 KeyNameToCode:= code; |
|
67 end; |
|
68 |
|
69 procedure MaskModifier(var code: LongInt; Modifier: LongWord); |
|
70 begin |
|
71 WriteLnToConsole(inttostr(code)); |
|
72 code:= code or (modifier shl 10); |
|
73 WriteLnToConsole(inttostr(code)); |
|
74 end; |
|
75 |
|
76 procedure MaskModifier(Modifier: shortstring; var code: LongInt); |
|
77 var mod_ : shortstring; |
|
78 ModifierCount, i: LongInt; |
|
79 c : char; |
|
80 begin |
|
81 if Modifier = '' then exit; |
|
82 ModifierCount:= 0; |
|
83 for c in Modifier do |
|
84 if(c = ':') then inc(ModifierCount); |
|
85 |
|
86 SplitByChar(Modifier, mod_, ':');//remove the first mod: part |
|
87 Modifier:= mod_; |
|
88 for i:= 0 to ModifierCount do |
|
89 begin |
|
90 mod_:= ''; |
|
91 SplitByChar(Modifier, mod_, ':'); |
|
92 WriteLnToConsole(Modifier + ' baaaaa' ); |
|
93 if (Modifier = 'lshift') then code:= code or (KMOD_LSHIFT shl 10); |
|
94 if (Modifier = 'rshift') then code:= code or (KMOD_RSHIFT shl 10); |
|
95 if (Modifier = 'lalt') then code:= code or (KMOD_LALT shl 10); |
|
96 if (Modifier = 'ralt') then code:= code or (KMOD_RALT shl 10); |
|
97 if (Modifier = 'lctrl') or (mod_ = 'lmeta') then code:= code or (KMOD_LCTRL shl 10); |
|
98 if (Modifier = 'rctrl') or (mod_ = 'rmeta') then code:= code or (KMOD_RCTRL shl 10); |
|
99 Modifier:= mod_; |
|
100 end; |
60 end; |
101 end; |
61 |
102 |
62 procedure ProcessKey(code: LongInt; KeyDown: boolean); |
103 procedure ProcessKey(code: LongInt; KeyDown: boolean); |
63 var |
104 var |
64 Trusted: boolean; |
105 Trusted: boolean; |
65 s : string; |
106 s : string; |
66 begin |
107 begin |
67 |
108 WriteLnToConsole(inttostr(code) + ' KeyDown:' + inttostr(ord(keydown)) + CurrentBinds[code]) ; |
68 if not(tkbd[code] xor KeyDown) then exit; |
109 if not(tkbd[code] xor KeyDown) then exit; |
69 tkbd[code]:= KeyDown; |
110 tkbd[code]:= KeyDown; |
70 |
|
71 |
111 |
72 hideAmmoMenu:= false; |
112 hideAmmoMenu:= false; |
73 Trusted:= (CurrentTeam <> nil) |
113 Trusted:= (CurrentTeam <> nil) |
74 and (not CurrentTeam^.ExtDriven) |
114 and (not CurrentTeam^.ExtDriven) |
75 and (CurrentHedgehog^.BotLevel = 0); |
115 and (CurrentHedgehog^.BotLevel = 0); |
76 |
|
77 |
|
78 |
116 |
79 // ctrl/cmd + q to close engine and frontend |
117 // ctrl/cmd + q to close engine and frontend |
80 if(KeyDown and (code = quitKeyCode)) then |
118 if(KeyDown and (code = quitKeyCode)) then |
81 begin |
119 begin |
82 {$IFDEF DARWIN} |
120 {$IFDEF DARWIN} |