Jump to content

AdLibRegister


Recommended Posts

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...