Tuesday, September 2, 2008

AHK - Send() - My custom send function

This function allows you to insert pauses in your text via "{_Sleep ####}" added anywhere in your text, where "####" is the number of milliseconds to sleep/pause. You can also set the mode (ie. play, event) with the Mode parameter, omit this parameter to use the default.
Send(Text,Mode="") {
If (Mode)
SendMode %Mode%
FoundPos := 0
Loop {
If (!FoundPos := RegExMatch(Text,"Ui).*\{_Sleep \d+\}",Match,++FoundPos))
Break
FoundPos += StrLen(Match) - 1
Send % RegExReplace(Match,"Ui)(.*)\{_Sleep \d+\}","$1")
Sleep % RegExReplace(Match,"Ui).*\{_Sleep (\d+)\}","$1")
}
Send % SubStr(Text,FoundPos)
}

Example:
Send("{_Sleep 2000}a{_Sleep 1000}b","Input")

No comments: