I do somthing similar as well.
Code:
#include <Misc.au3>
HotKeySet('{END}', 'Quit')
HotKeySet('{F10}', 'Pause')
Global $Paused
Global $DebugOn = False
Global $delay = 250
Pause()
;=======CODE HERE=============
While 1
WEnd
;=======CODE HERE=============
Func pix()
Sleep(1000)
$coord = PixelSearch(0, 0, 100, 200, 0xFF0000)
If Not @error Then
MouseClick("primary", $coord[0], $coord[1], 1, 0)
EndIf
EndFunc
Func Quit()
Exit
EndFunc
Func Pause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc
Func DEBUG($MESSAGE)
If $DebugOn Then
ToolTip($MESSAGE, 0, 0)
EndIf
EndFunc ;==>Debug Info