I initially thought this was a trivial problem, but later realised it wasn't so straightforward.
It is actually a variation of the "stop repeating action without exiting the script" problem as mentioned in the FAQ:
http://www.autohotkey.com/docs/FAQ.htm#repeat
At some point, for example, you may want to press Alt-11 or Alt-33, which is actually Alt-1 twice in a row, or Alt-3 twice in a row.
With that in mind, I've modified the FAQ script to handle all double-press alt combinations for 2, 3, and 4. Launch the script, and try pressing Alt-42, Alt-23, Alt-33, etc.
Unfortunately, this is an "exponential" solution, so if you want to handle all 10 digits, the script will have be much longer.
Code:
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: WinXP/Vista
; Author: Lemming
;
; Script Function:
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Alt-2
#MaxThreadsPerHotkey 3
!2::
#MaxThreadsPerHotkey 1
If Alt2BeingPressed
{
MsgBox,Alt-2-2 was pressed!
Alt2BeingPressed:= false ; Signal that thread's loop to stop
return ; End this thread so that the one underneath will resume and see the change made by the line above.
}
If Alt3BeingPressed
{
MsgBox,Alt-3-2 was pressed!
Alt2BeingPressed:= false ; Signal that thread's loop to stop
Alt3BeingPressed:= false ; Signal that thread's loop to stop
return ; End this thread so that the one underneath will resume and see the change made by the line above.
}
If Alt4BeingPressed
{
MsgBox,Alt-4-2 was pressed!
Alt2BeingPressed:= false ; Signal that thread's loop to stop
Alt4BeingPressed:= false ; Signal that thread's loop to stop
return ; End this thread so that the one underneath will resume and see the change made by the line above.
}
; Otherwise:
Alt2BeingPressed := true
Loop, 10
{
Sleep 50
if not Alt2BeingPressed
break
}
Alt2BeingPressed:= false ; Reset in preparation for the next press of this hotkey.
Return
; Alt-3
#MaxThreadsPerHotkey 3
!3::
#MaxThreadsPerHotkey 1
If Alt2BeingPressed
{
MsgBox,Alt-2-3 was pressed!
Alt2BeingPressed:= false ; Signal that thread's loop to stop
Alt3BeingPressed:= false ; Signal that thread's loop to stop
return ; End this thread so that the one underneath will resume and see the change made by the line above.
}
If Alt3BeingPressed
{
MsgBox,Alt-3-3 was pressed!
Alt3BeingPressed:= false ; Signal that thread's loop to stop
return ; End this thread so that the one underneath will resume and see the change made by the line above.
}
If Alt4BeingPressed
{
MsgBox,Alt-4-3 was pressed!
Alt3BeingPressed:= false ; Signal that thread's loop to stop
Alt4BeingPressed:= false ; Signal that thread's loop to stop
return ; End this thread so that the one underneath will resume and see the change made by the line above.
}
; Otherwise:
Alt3BeingPressed := true
Loop, 10
{
Sleep 50
if not Alt3BeingPressed
break
}
Alt3BeingPressed:= false ; Reset in preparation for the next press of this hotkey.
Return
; Alt-4
#MaxThreadsPerHotkey 3
!4::
#MaxThreadsPerHotkey 1
If Alt2BeingPressed
{
MsgBox,Alt-2-4 was pressed!
Alt2BeingPressed:= false ; Signal that thread's loop to stop
Alt4BeingPressed:= false ; Signal that thread's loop to stop
return ; End this thread so that the one underneath will resume and see the change made by the line above.
}
If Alt3BeingPressed
{
MsgBox,Alt-3-4 was pressed!
Alt3BeingPressed:= false ; Signal that thread's loop to stop
Alt4BeingPressed:= false ; Signal that thread's loop to stop
return ; End this thread so that the one underneath will resume and see the change made by the line above.
}
If Alt4BeingPressed
{
MsgBox,Alt-4-4 was pressed!
Alt4BeingPressed:= false ; Signal that thread's loop to stop
return ; End this thread so that the one underneath will resume and see the change made by the line above.
}
; Otherwise:
Alt4BeingPressed := true
Loop, 10
{
Sleep 50
if not Alt4BeingPressed
break
}
Alt4BeingPressed:= false ; Reset in preparation for the next press of this hotkey.
Return