Sign in to follow this  
Followers 0
Noviceatthis

AdLibRegister

4 posts in this topic

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

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

Ah, I see, thank you both :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0