Показать полную графическую версию : [решено] Вопрос по TrayItemSetOnEvent: как выйти из скрипта в данной ситуации?
Добрый день! Для иллюстрации проблемы я сделал маленький скрипт:
$ExitLoop=1
Opt("TrayMenuMode",1)
Opt("TrayOnEventMode",1)
HotKeySet("{esc}","ExitFunc")
$CurrentTime=TrayCreateItem("StartLoop")
TrayItemSetOnEvent ( -1, "StartLoop" )
$Exit=TrayCreateItem("Exit")
TrayItemSetOnEvent ( -1, "ExitFunc" )
while 1
sleep(100)
wend
Func StartLoop()
m("StartLoop() starts")
if $ExitLoop=1 then
$ExitLoop=0
else
$ExitLoop=1
endif
while not $ExitLoop
sleep(100)
wend
EndFunc
Func ExitFunc()
m("ExitFunc() starts")
Exit
EndFunc
Проблема вот в чем: когда щелкаешь на опцию трея "StartLoop", программа перестает реагировать на все остальные команды юзера через меню трея (потому что StartLoop зацикливает там все). А вот HotKeySet работает прекрасно вне зависимости от того, была ли нажата кнопка "StartLoop". Вопрос: как заставить прогу реагировать на команды через меню трея после вызова функции "StartLoop"?
программа перестает реагировать на все остальные команды юзера через меню трея »
Потому что обработка событии продолжается только после завершения вызванной событием функции - в этом случае лучше всего обрабатывать события в главном цикле:
$iLoop = False (http://www.autoitscript.com/autoit3/docs/keywords.htm#False)
Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)("TrayMenuMode", 1)
Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)("TrayOnEventMode", 1)
HotKeySet (http://www.autoitscript.com/autoit3/docs/functions/HotKeySet.htm)("{esc}", "ExitFunc")
$CurrentTime = TrayCreateItem (http://www.autoitscript.com/autoit3/docs/functions/TrayCreateItem.htm)("StartLoop")
TrayItemSetOnEvent (http://www.autoitscript.com/autoit3/docs/functions/TrayItemSetOnEvent.htm)(-1, "StartLoop")
$Exit = TrayCreateItem (http://www.autoitscript.com/autoit3/docs/functions/TrayCreateItem.htm)("Exit")
TrayItemSetOnEvent (http://www.autoitscript.com/autoit3/docs/functions/TrayItemSetOnEvent.htm)(-1, "ExitFunc")
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(100)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iLoop Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Loop_Proc()
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) StartLoop()
;m("StartLoop() starts")
$iLoop = Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) $iLoop
$sText = "StartLoop"
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iLoop Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $sText = "StopLoop"
TrayItemSetText (http://www.autoitscript.com/autoit3/docs/functions/TrayItemSetText.htm)($CurrentTime, $sText)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) Loop_Proc()
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) $iLoop
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(100)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) ExitFunc()
;m("ExitFunc() starts")
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.
Available in ZeroNet 1osznRoVratMCN3bFoFpR2pSV5c9z6sTC