Mike25de Posted November 22, 2014 Posted November 22, 2014 Hi, I have a gui and a function that has a sleep of 20 sec. While the script is in the SLEEP period, i can not close the gui (exit). I have created my own exit button .. or the window close button... neither of them work. How can i trigger another action while the script is sleeping? Thanks in advance
water Posted November 22, 2014 Posted November 22, 2014 Something like this? HotKeySet("{F7}", _Exit) Sleep(10000) Func _Exit() Exit EndFunc ;==>_Exit My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
BrewManNH Posted November 22, 2014 Posted November 22, 2014 Easiest way to accomplish this would be to not use sleep, use TimerInit and TimerDiff to do it instead and then you won't have to worry about it. There are dozens of examples of how to do this on the forum. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Mike25de Posted November 22, 2014 Author Posted November 22, 2014 Thank you all .. i will try to use timer functions.
Mike25de Posted November 23, 2014 Author Posted November 23, 2014 (edited) Guys... i might just be retarded ... but i have the same problem with timerinit... i can not click other button.. while i am waiting for 17 sec. Please check the code below.. When i press the $GUI_Button_Test button.. the timer starts - it works just fine... BUT while this timer is active... pressing the Exit button... doesn't stop/Exit.... until the Timer is done. Even if i press the Exit after 2 seconds.. the timer will wait until the WHILE loop finishes and only then the exit action is activated. I want to know if there is a way to break the timer.. to trigger another button while the timer is still active. Am i doing something wrong? Case $msg = $GUI_Button_Exit Exit 0 Case $msg = $GUI_Button_Test Local $max = 17 ;wait this many seconds Local $hTimer = TimerInit() ; Begin the timer While 1 Local $fDiff = TimerDiff($hTimer) / 1000 ; transform into sec If $fDiff >= $max Then ExitLoop EndIf Sleep(200) WEnd MsgBox($MB_SYSTEMMODAL, "Time Difference", $fDiff) Edited November 23, 2014 by IAHIM
water Posted November 23, 2014 Posted November 23, 2014 Why do you use Sleep at all? What is you script waiting for? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Mike25de Posted November 23, 2014 Author Posted November 23, 2014 Why do you use Sleep at all? What is you script waiting for? My script is waiting for some files/feeds from a remote server. I don't want to connect to that server every second... but wait for half a minute. And i want to be able to trigger a second function while the script is sleeping....
Solution bogQ Posted November 23, 2014 Solution Posted November 23, 2014 you declared loop in a loop so you are traped inside itone of the many wayes to do what you need can be like this expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Local $hGUI = GUICreate("Example", 400, 100) Local $GUI_Button_Exit = GUICtrlCreateButton("Exit", 10, 10, 85, 25) Local $GUI_Button_Test = GUICtrlCreateButton("test", 120, 10, 85, 25) GUISetState() $isITclicked = False $FirstLoop = False Local $hTimer, $max = 18;wait this many seconds While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_Button_Exit Exit 0 Case $GUI_Button_Test ;~ If Not $isITclicked And Not $FirstLoop Then;enable to dont restart counting seconds if it already started $isITclicked = True $FirstLoop = True ;~ EndIf EndSwitch If $isITclicked Then If $FirstLoop Then $FirstLoop = False $hTimer = TimerInit() ; Begin the timer EndIf Local $fDiff = TimerDiff($hTimer) / 1000 ; transform into sec If $fDiff >= $max Then MsgBox($MB_SYSTEMMODAL, "Time Difference", $fDiff) $isITclicked = False ToolTip('') Else ToolTip($fDiff) EndIf EndIf WEndthere is ofc AdlibRegister func that can do similar things you need TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.
kylomas Posted November 23, 2014 Posted November 23, 2014 (edited) just for grins, another way... expandcollapse popup#include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <date.au3> local $gui010 = guicreate('') local $aSize = wingetclientsize($gui010) local $edt010 = guictrlcreateedit('',10,20,$aSize[0]-20,300,bitor($es_readonly,$WS_VSCROLL)) local $lbl010 = guictrlcreatelabel('',10,$aSize[1]-70,$aSize[0]-20,20,$ss_center) local $btn010 = guictrlcreatebutton('Start Timer',10,$aSize[1]-40,$aSize[0]-20,20) guisetstate() local $st = 0, $started = false while 1 switch guigetmsg() case $gui_event_close Exit case $btn010 switch guictrlread($btn010) case 'Start Timer' $st = timerinit() $started = not $started guictrlsetdata($edt010,'Timer Started at ' & _now() & @CRLF,1) guictrlsetdata($btn010,'Stop Timer') case 'Stop Timer' $started = not $started guictrlsetdata($edt010,'Timer Stopped at ' & _now() & @CRLF,1) guictrlsetdata($btn010,'Start Timer') endswitch EndSwitch if $started then if int(timerdiff($st)/1000) > 17 then if FileExists('some.file') then ; ; go do something ; EndIf $st = timerinit() guictrlsetdata($edt010,'Timer Restarted at ' & _now() & @CRLF,1) endif if guictrlread($lbl010) <> int(timerdiff($st/1000)) then guictrlsetdata($lbl010,int(timerdiff($st)/1000)) endif WEnd Edited November 23, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now