Then:
Code: Select all
#IFWinActive, ahk_exe notepad.exe
$*d:: ; $* both modifier required!
keywait, d, T0.5
if errorlevel {
SoundBeep
SendTimer(1, " ; long press starts SendTimer no. 1
( LTrim Join C
{Ctrl Down}{Shift Down}{h}{Shift Up}{Ctrl Up} ; ^+h
{100} ; Sleep 100
{Ctrl Down}{m}{Ctrl Up} ; ^m
{500} ; Sleep 500
L ; L
)")
} else Send d ; short press
keywait, d
SendTimer(-1) ; SendTimer no. 1 is cancelled when key D is released
return
#IFWinActive
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SendTimer(N, Output:="", Delay:=-100, AddRandom:=0)
{ Local D, C ;global Pseudo-Arrays: Ο%%, Τ%%, Δ%%, Ρ%%
If (N>0 And Ο%N%>"") ;Update lock
Return ;with Ο:Omikron, Τ:Tau, Δ:Delta, P:Rho
Critical,% (C:=A_IsCritical)?:"Off"
N:=Abs(N), Ο%N%:=Τ%N%:=Output, D:=Abs(Δ%N%:=Delay)
Random, D, D, D+Ρ%N%:=AddRandom, N:=Func("T").Bind(N)
SetTimer,% N,% (""<Output)?D*(Delay>0):"Off"
Critical,% C?:"Off" ;restore original criticality
Return
}
T(N) ; called by SendTimer(), Timer function
{ Static Needle:="\{([0-9\-]{2,}|%.+%)\}|\{[^\}]*\}|."
, BlindText:="{Blind}{Text}", Label:="SendTimerOff-"
Critical
Random, D, D:=Abs(Δ%N%),D+Ρ%N%,RegExMatch(Τ%N%,Needle,K)
Random, K1, !(R:=StrSplit(K1,"-")) R.1, Max(0 R.1, 0 R.2)
SendInput,% (StrLen(K)=1)?BlindText K:(K1?:D(K))
SetTimer,,% D:=("0"<K1 Τ%N%:=StrReplace(Τ%N%, K,,, 1))
?Max(D, K1?D(K1):0):(Δ%N%>0)?(D, Τ%N%:=Ο%N%):"Off"
IF !++D And (!Ο%N%:="") And IsLabel(D:=Label N)
SetTimer,% D, -10 ;jump to Label SendTimerOff-N
Exit
}
D(K) ; called by T(), Deref function expands variable references
{ Static Needle := "%(.*?)%", Pos:=1
While, Pos:=RegExMatch(K, Needle, M, Old:=Pos+StrLen(M))
Out .= SubStr(K, Old, Pos-Old) %M1%
Return, Out SubStr(K, Old), Pos:=1
}
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SendTimer(N [, Output, Delay, AddRandom ])
SendTimerOff-N:
SendTimer() creates and terminates any number of independent timers which automatically and repeatedly send a respective Output.
The timers do not use Sleep, KeyWait, SetKeyDelay, or any other time robbers that prevent threads from ending. Often even external KeyWait and due to a built-in repeat function, Loops can be saved.
SendTimer() acts globally, but the only global variables are four pseudo-arrays named with Greek capital letters. All others variables are neither global (nor Greek).
N: Integer number of the timer.
N > 0: the timer with number N will be created, an update will be prevented.
N < 0: the timer with the number of the absolute value of N will be updated or created.
An updated timer without Output will be terminated. E.g. SendTimer(-2) stops Timer 2.
When the timer N ends, the label SendTimerOff-N is jumped to, if present.
Output: A string consisting of Text, Keys, Clicks, and Local Delays.
Text: e.g. "Hello world!" is sent with SendInput in blind text mode.
{Key}: e.g. "{Ctrl down}{c}{Ctrl up}" are sent with SendInput.
{Click [Options]}: e.g. {Click 100 200 Right} or {Click, %X% , %Y%, %Button%}
Variable references %Variable% within {..} will be extended currently).
Delay: the absolute value of Delay determines the delay in milliseconds, after each sent text character, key or click.
> 0: the Output of the timer is repetitive.
< 0: the Output is done once.
AddRandom: Random increase of the delay by up to (additive) AddRandom in milliseconds.
{Inline Delay}: e.g. "{1000}, {-2000}, {100-300} replaces the next delay
if that is smaller. Random delay 50 - 1000 ms: {50-1000}