Noviceatthis Posted February 24, 2013 Share Posted February 24, 2013 Hello all Would somebody be able to tell me why the adlibregister function is necessary in the following script #include <timers.au3> Global $iLimit = 5 ; idle limit in seconds HotKeySet("{ESC}", "_Quit") AdlibRegister("_CheckIdleTime", 500) While 1 Sleep(20) WEnd Func _CheckIdleTime() If _Timer_GetIdleTime() > $iLimit * 1000 Then MsgBox(16, "Timeout", "You haven't done anything in " & $iLimit & " seconds... Get busy!", 3) EndFunc ;==>_CheckIdleTime Func _Quit() Exit EndFunc ;==>_Quit much appreciated Link to comment Share on other sites More sharing options...
kylomas Posted February 24, 2013 Share Posted February 24, 2013 Noviceatthis, Using an adlib function is just one way to implement running a function iteratively. In this case the function is run every 1/2 second. However, when you read the help file for adlibregister you will find that you should NOT use blocking functions in adlibs (msgbox, for example). A better way to implement thi would be to pass a switch like this: #include <timers.au3> Global $iLimit = 3 ; idle limit in seconds HotKeySet("{ESC}", "_Quit") AdlibRegister("_CheckIdleTime", 500) Local $expired = False While 1 Sleep(20) If $expired Then MsgBox(16, "Timeout", "You haven't done anything in " & $iLimit & " seconds... Get busy!", 3) $expired = Not $expired EndIf WEnd Func _CheckIdleTime() If _Timer_GetIdleTime() > $iLimit * 1000 Then $expired = True EndFunc ;==>_CheckIdleTime Func _Quit() Exit EndFunc ;==>_Quit 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 Link to comment Share on other sites More sharing options...
JohnOne Posted February 24, 2013 Share Posted February 24, 2013 Because if it wasn't there the function would never be called. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Noviceatthis Posted February 24, 2013 Author Share Posted February 24, 2013 Ah, I see, thank you both Link to comment Share on other sites More sharing options...
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