3 changed files with 69 additions and 81 deletions
@ -1,97 +1,87 @@ |
|||
; |
|||
; Functions for holding and repeating keys |
|||
|
|||
; |
|||
; Internal Functions |
|||
; |
|||
|
|||
_HoldRepeat_TurboOn := Map() |
|||
_HoldRepeat_LoopState := Map() |
|||
_HoldRepeat_IsActive := Map() |
|||
|
|||
_GetPrefix(SendBlind) { |
|||
if (SendBlind) { |
|||
return "{Blind}" |
|||
} else { |
|||
return "" |
|||
} |
|||
_HoldRepeat_Handler(Mode, TargetKey, CancelKeys:=[], HoldKey?, BlindMode:="{Blind}") { |
|||
global _HoldRepeat_IsActive |
|||
if (_HoldRepeat_IsActive.Has(TargetKey) AND _HoldRepeat_IsActive[TargetKey]) { |
|||
return |
|||
} |
|||
_HoldRepeat_IsActive[TargetKey] := true |
|||
|
|||
Hold(Primary, Secondary:=[], Tertiary:=[], SendBlind:=true) { |
|||
Prefix := _GetPrefix(SendBlind) |
|||
Send Prefix "{" Primary " down}" |
|||
SetTimer HoldLoop.Bind(Primary,Secondary,Tertiary,Prefix), 50 |
|||
Send BlindMode "{" TargetKey " down}" |
|||
if (Mode == "Hold") { |
|||
if _HoldRepeat_LoopState.Has(TargetKey) { |
|||
_HoldRepeat_LoopState.Delete(TargetKey) |
|||
} |
|||
|
|||
HoldLoop(Primary, Secondary, Tertiary, Prefix) { |
|||
if GetKeyState(Primary,"P") { |
|||
SetTimer , 0 |
|||
} else if (Mode == "Repeat") { |
|||
_HoldRepeat_LoopState[TargetKey] := true |
|||
} else { |
|||
return |
|||
} |
|||
for index,key in Secondary { |
|||
SetTimer _HoldRepeat_Loop.Bind(TargetKey,CancelKeys,HoldKey?,BlindMode), 50 |
|||
} |
|||
|
|||
_HoldRepeat_Loop(TargetKey, CancelKeys, HoldKey?, BlindMode:="{Blind}") { |
|||
global _HoldRepeat_LoopState |
|||
global _HoldRepeat_IsActive |
|||
|
|||
endLoop := false |
|||
for index,key in CancelKeys { |
|||
if GetKeyState(key,"P") { |
|||
Send Prefix "{" Primary " up}" |
|||
SetTimer , 0 |
|||
return |
|||
Send BlindMode "{" TargetKey " up}" |
|||
endLoop := true |
|||
} |
|||
} |
|||
keyHeld:=!Tertiary.Length |
|||
for index,key in Tertiary { |
|||
if GetKeyState(key) { |
|||
keyHeld:=1 |
|||
break |
|||
if IsSet(HoldKey) { |
|||
if !GetKeyState(HoldKey,"P") { |
|||
Send BlindMode "{" TargetKey " up}" |
|||
endLoop := true |
|||
} |
|||
} else { |
|||
if GetKeyState(TargetKey,"P") { |
|||
endLoop := true |
|||
} |
|||
} |
|||
if (!keyHeld) { |
|||
Send Prefix "{" Primary " up}" |
|||
if endLoop { |
|||
SetTimer , 0 |
|||
_HoldRepeat_IsActive[TargetKey] := false |
|||
return |
|||
} |
|||
} |
|||
|
|||
Repeat(Primary, Secondary:=[], SendBlind:=true) { |
|||
Prefix := _GetPrefix(SendBlind) |
|||
Send Prefix "{" Primary " up}" |
|||
Sleep 100 |
|||
RepeatVar := 0 |
|||
Loop { |
|||
if GetKeyState(Primary,"P") { |
|||
return |
|||
} |
|||
for index,key in Secondary { |
|||
if GetKeyState(key,"P") { |
|||
return |
|||
} |
|||
} |
|||
if (RepeatVar == 0) { |
|||
Send Prefix "{" Primary " down}" |
|||
RepeatVar := 1 |
|||
} else { |
|||
Send Prefix "{" Primary " up}" |
|||
RepeatVar := 0 |
|||
} |
|||
Sleep 50 |
|||
if _HoldRepeat_LoopState.Has(TargetKey) { |
|||
updown := (_HoldRepeat_LoopState[TargetKey] ? "up" : "down") |
|||
Send BlindMode "{" TargetKey " " updown "}" |
|||
_HoldRepeat_LoopState[TargetKey] := !_HoldRepeat_LoopState[TargetKey] |
|||
} |
|||
} |
|||
|
|||
; |
|||
; Internal Functions |
|||
; |
|||
|
|||
Hold := _HoldRepeat_Handler.Bind("Hold") |
|||
Repeat := _HoldRepeat_Handler.Bind("Repeat") |
|||
|
|||
; Sets key to hold if single tap, or repeat if double tap |
|||
HoldOrRepeat(Primary, Secondary:=[], SendBlind:=True) { |
|||
Send _GetPrefix(SendBlind) "{" Primary " down}" |
|||
if KeyWait(Primary, "D T0.2") { |
|||
Repeat(Primary,Secondary,SendBlind) |
|||
HoldOrRepeat(TargetKey, CancelKeys?, BlindMode:="{Blind}") { |
|||
Send BlindMode "{" TargetKey " down}" |
|||
if KeyWait(TargetKey, "D T0.2") { |
|||
mode := "Repeat" |
|||
} else { |
|||
Hold(Primary,Secondary,,SendBlind) |
|||
mode := "Hold" |
|||
} |
|||
_HoldRepeat_Handler(mode, TargetKey, CancelKeys,, BlindMode) |
|||
} |
|||
|
|||
; Press Target button extremely rapidly while Hold button is held down |
|||
Turbo(Target, Hold:=Target) { |
|||
global _HoldRepeat_TurboOn |
|||
If (_HoldRepeat_TurboOn.Has(Target "_" Hold) and _HoldRepeat_TurboOn[Target "_" Hold]) { |
|||
return |
|||
} else { |
|||
_HoldRepeat_TurboOn[Target "_" Hold]:=1 |
|||
While GetKeyState(Hold,"P") { |
|||
SendEvent "{Blind}{" Target " down}" |
|||
Sleep 10 |
|||
SendEvent "{Blind}{" Target " up}" |
|||
Sleep 10 |
|||
} |
|||
_HoldRepeat_TurboOn[Target "_" Hold]:=0 |
|||
Turbo(TargetKey, HoldKey:=TargetKey,BlindMode:="{Blind}") { |
|||
While GetKeyState(HoldKey,"P") { |
|||
Send BlindMode "{" TargetKey "}" |
|||
} |
|||
} |
Loading…
Reference in new issue