My guess is, then, that if I change my loop to a subroutine, then the OnEvent will work similarly to how I had WaitKeyDown protect the entrance to a loop.
That's correct.
As an attempt for clarity, lets examine the use of OnEvent>Key_Down one section at a time.
First, the Line:
Code: Select all
OnEvent>Key_Down,VK32,0,SubRoutineName
Sets a condition for the script. When this condition is met the script will immediately jump to the subroutine called by the OnEvent. For this OnEvent to function two things have to happen.
1) The script must be processing, it can't be in a "Wait" mode. If the script is "waiting" (Wait>, WaitWindowOpen>, WaitKeyDown>, etc) OnEvent events are not processed.
2) The OnEvent condition must be met. In this case the space key must be pressed.
Typically the script will be in an idling loop waiting for a OnEvent condition to be met. While in the "idling" loop, the script can be checking for and or setting conditions on the computer that might be needed by the script. For example making sure a particular window maintains focus. Or checking to see what applications are running.
Code: Select all
Label>Loop
SetFocus>WindowThatWillBeTheSpaceKeyTrashCan
Wait>0.01
Goto>Loop
At the moment the space key is pressed the script immediately jumps to the subroutine specified in the OnEvent line. When the subroutine has finished, unless the script is terminated during the subroutine, the script returns to the next line after the last line processed in the "idle" loop.
Code: Select all
SRT>SubRoutineName
//Do stuff
END>SubRoutineName
Put the sections together and you get pretty much the sample I posted above.
Code: Select all
OnEvent>Key_Down,VK32,0,SubRoutineName
SRT>SubRoutineName
//Do stuff
END>SubRoutineName
Label>Loop
SetFocus>WindowThatWillBeTheSpaceKeyTrashCan
Wait>0.01
Goto>Loop