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