@mikeyww thank you, I see the problem if ONE loop takes a long time to run . Can you give another example ?
( if the loop is for shorttime then it's OK to use F1 otherwise break with F4 ( or maybe close also program process ) )
Code: Select all
/*
start script , Button is OFF
F1 start , Button is ON
loop is running until use F1 again > Button is OFF
but you can't break if something running , ( here keeps msgbox for 10 seconds )
you can break msgbox running when use F4 ( RELOAD )
If the loop is for shorttime then it's OK to use F1
ESC to quit this script
*/
;- a test script for loop
#MaxThreadsPerHotkey 2
#warn
Filename1=Colorbotton
setworkingdir,%a_scriptdir%
Gui,2:Font,Cdefault,Fixedsys
Gui,2:Color,Black
z:=""
Gui,2:Color, EEAA99
Gui,2:Add,Progress, x10 y20 w100 h23 Disabled BackgroundGreen vC2
Gui,2:Add,Text, xp yp wp hp cYellow BackgroundTrans Center 0x200 vB2 gStart,ON
Gui,2:Add,Progress, xp yp wp hp Disabled BackgroundRED vC1
Gui,2:Add,Text, xp yp wp hp cYellow BackgroundTrans Center 0x200 vB1 gStart,OFF
Gui,2: Show, x10 y1 w200 h60 ,%filename1%
Gui 2:+LastFound +ToolWindow +AlwaysOnTop
WinSet, TransColor, EEAA99
Gui,2:-Caption
return
;-------------------------
F4::reload
esc::exitapp
;-------------------------
~$F1::
start:
gui,2:submit,nohide
z:=!z
if z
{
GuiControl,2: hide,B1
GuiControl,2: hide,C1
GuiControl,2: show,B2
GuiControl,2: show,C2
loop
{
if (!z)
break
msgbox, 262208,PIXELSEARCH ,Running,.5
sleep,1000
msgbox, 262208,PIXELSEARCH-CONTINUE ,Wait 10 seconds`nOR use F4 to Reload,10
}
;Until (!z)
msgbox, 262208,PIXELSEARCH,LOOP ENDED in ON-Sector,3
}
else
{
GuiControl,2: hide,B2
GuiControl,2: hide,C2
GuiControl,2: show,B1
GuiControl,2: show,C1
msgbox, 262208,,You are in OFF-Sector,1
}
return
;=============================================================
a short script , toggle with F9 to immediately break a loop
Code: Select all
;- a test script for loop / see Button ON/OFF
;- if ONE loop takes longtime break with F9 and start again with F9
#Warn
#MaxThreadsPerHotkey 2
Filename1=Colorbotton
setworkingdir,%a_scriptdir%
Gui,2: -dpiscale -caption +Alwaysontop
Gui,2:Font,CYellow S14,Lucida Console
z:=""
Gui,2:Add,Progress,x0 y0 w300 h60 Disabled BackgroundGreen vC2
Gui,2:Add,Text, xp yp wp hp cYellow BackgroundTrans Center 0x200 vB2 gStart,Loop-ON (F9)
Gui,2:Add,Progress, xp yp wp hp Disabled BackgroundRED vC1
Gui,2:Add,Text, xp yp wp hp cYellow BackgroundTrans Center 0x200 vB1 gStart,Loop-OFF (F9)
Gui,2: Show,x100 y100 w300 h60 ,%filename1%
return
;-------------------------
esc::exitapp
;-------------------------
$F9::
start:
gui,2:submit,nohide
z:=!z
if (z)
{
GuiControl,2: hide,B1
GuiControl,2: hide,C1
GuiControl,2: show,B2
GuiControl,2: show,C2
loop
{
if (!z)
break
sleep,200
msgbox, 262208,LOOP-Running Continous ,This waits 10 seconds`nOR use F9 again to Reload`nESC to quit this script,10
}
;Until (z) ;- loop only once
;msgbox, 262208,LOOP-END,LOOP ENDED in ON-Sector,2
return
}
else
reload
return
;=======================================================