Jump to content

Local sleep ?


MARAN
 Share

Recommended Posts

Is there anyway to make an local sleep, not the entire script like Sleep does?

I.e.:

Func Test1()
    MsgBox(0, "", "Click OK and wait 5 seconds.")
    LocalSleep(5000)
    MsgBox(0, "", "Done.")
EndFunc

Test1()

It mean that it will stop the execution of the function for 5 secs. and not the entire script. It would be useful for GUIs that require a non-stop loop (so it can get the events like $GUI_EVENT_CLOSE without delay).

Edited by MARAN
Link to comment
Share on other sites

Is there anyway to make an local sleep, not the entire script like Sleep does?

I.e.:

Func Test1()
    MsgBox(0, "", "Click OK and wait 5 seconds.")
    LocalSleep(5000)
    MsgBox(0, "", "Done.")
EndFunc

Test1()

It mean that it will stop the execution of the function for 5 secs. and not the entire script. It would be useful for GUIs that require a non-stop loop (so it can get the events like $GUI_EVENT_CLOSE without delay).

sorry bro.I`m newbie in Autoscript but IMHO you can use sleep utility(NOTE: Third party Utlility )

with this scenario:

run("sleep.exe 5")

If you want to use third party utility for this reason search on mS.

Edited by Sh3llC043r
[size="5"] [/size]
Link to comment
Share on other sites

sorry bro.I`m newbie in Autoscript but IMHO you can use sleep utility(NOTE: Third party Utlility )

with this scenario:

run("sleep.exe 5")

If you want to use third party utility for this reason search on mS.

I don't think that this would help him, the script gets paused at the message box and can't execute anything before its closed.
[font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size]
Link to comment
Share on other sites

Just run the GUI in event mode. GuiSetOnEvent($GUI_EVENT_CLOSE, "_GuiClosed") would get triggered even during a Sleep().

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Is there anyway to make an local sleep, not the entire script like Sleep does?

I.e.:

Func Test1()
    MsgBox(0, "", "Click OK and wait 5 seconds.")
    LocalSleep(5000)
    MsgBox(0, "", "Done.")
EndFunc

Test1()

It mean that it will stop the execution of the function for 5 secs. and not the entire script. It would be useful for GUIs that require a non-stop loop (so it can get the events like $GUI_EVENT_CLOSE without delay).

Actually I think you could do what you want although it depends on what the finction is like that you want to delay. Suppose you call a function that has to execute various steps or stages. Suppose you call the function and it decides that after completing step 3 that it should wait for 5 seconds before going on to step 4. So it could return to the main script and which would carry on running, then after the delay of 5 sec return to the function and carry on from where it left off. I think this would be reasonbly simple if you used the Beta version because now we have static variables. So you could do something like this.

(Take into account that I'm making this up as I type.)

while something
 switch somevariable
 case feed the dog:
 feeddog;
 case cleancar;
 callwife;
 case pausablefunction
    pausefunc()
 endswitch
wend


Func pausefunc($reset)
AdlibUnregister("pausefunc")
Static $step=1, $a,$b,$c....
Static $KeepGoing = True

If $reset then $step = 1
while $keepgoing
 switch step
    Case 1
    various code
    $step = 2
 Case 2
    ;....
    $step = 3
 Case 3
 ;....
    $step = 4; the next step to execute
    if $a = 9 then;some condition for a pause
    Adlibregister("pausefunc",5000);delay this function for 5 seconds
    return
    endif
 Case 4...
 If con1 then; just ideas
    $step = 6; miss a step out
 elseif cond2 then
    $step = 5
 else
    $keepgoing = false
    $step = 1
    endif


 etc
 EndFunc

Obviously I haven't tried this idea but it sounds reasonable to me.

EDIT: Since Static variables are not quite ready yet, as PsaltyDS pointed out in a post below, the same idea can be used but with global variables instead declared in the head of the main script

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Actually I think you could do what you want although it depends on what the finction is like that you want to delay. Suppose you call a function that has to execute various steps or stages. Suppose you call the function and it decides that after completing step 3 that it should wait for 5 seconds before going on to step 4. So it could return to the main script and which would carry on running, then after the delay of 5 sec return to the function and carry on from where it left off. I think this would be reasonbly simple if you used the Beta version because now we have static variables. So you could do something like this.

(Take into account that I'm making this up as I type.)

/hijack sorry..

Static Variables? Curious, what is this about? Very interesting.

EndFuncAutoIt is the shiznit. I love it.
Link to comment
Share on other sites

/hijack sorry..

Static Variables? Curious, what is this about? Very interesting.

If you touch them you get a small shock.

But I have heard a rumour that the Beta version comes with a help file, so perhaps (if that's true) then searching for 'static' might tell you.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I think this would be reasonbly simple if you used the Beta version because now we have static variables.

The Static keyword is being removed from the 3.3.1.x Beta release chain, and may reappear in the Betas after the next Production release of AutoIt. For now, don't count on using it.

I guess that's a reminder about depending of Beta features.

:)

Edit: Added linky.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The Static keyword is being removed from the 3.3.1.x Beta release chain, and may reappear in the Betas after the next Production release of AutoIt. For now, don't count on using it.

I guess that's a reminder about depending of Beta features.

:)

Edit: Added linky.

oh, thanks PsaltyDS, I'm glad you pointed that out to me. I was quite keen to start using static variables. Hopefully they will be included again soon.

EDIT: But that just means the idea I suggested could still be used only you would need to use global variables.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Use timer.. Let's say that you want to prevent users from entering value(disable input) for about 5 seconds, at the same time he can close the GUI:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 301, 201, 252, 136)
$Button1 = GUICtrlCreateButton("Click Me", 112, 112, 75, 25, $WS_GROUP)
$Input1 = GUICtrlCreateInput("Input1", 88, 64, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $init

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
    Case $Button1
        If BitAND(GUICtrlGetState($Input1),$GUI_ENABLE) = $GUI_ENABLE Then ; check if input is enabled
            $init = TimerInit() ; reset timer
            GUICtrlSetState($Input1,$GUI_DISABLE) ; disable input
        EndIf
    EndSwitch
    If BitAND(GUICtrlGetState($Input1),$GUI_DISABLE) = $GUI_DISABLE And TimerDiff($init) > 5000 Then GUICtrlSetState($Input1,$GUI_ENABLE) ; check if input is disabled AND time diff is more than 5 seconds
    Sleep(10)
WEnd

Hi ;)

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...