Wednesday, August 6, 2008

AHK - MultiPress()

This is a function I wrote that allows you to press a hotkey multiple times and have different things happen for the number of presses.
MultiPress(Max=-1)
{
Presses := 1
KeyWait, %A_ThisHotkey%
Loop
{
KeyWait, %A_ThisHotkey%, D T0.25
If (ErrorLevel || (Presses >= Max && Max > 0))
Break
Presses++
KeyWait, %A_ThisHotkey%
}
Return Presses
}
An example of use for this function is
a::
P := MultiPress()
MsgBox Pressed %A_ThisHotkey% %P% times!
Return

No comments: