Sign in to follow this  
Followers 0
loop21

2min timer loop for a mainsequence

7 posts in this topic

Hello im from Germany and i hope my english will be enough good.

So i want to script a loop of 2minute.

That loop starts with the timer (can be hidden without msgbox or else), that timer begins to count.

After it starts the mainprocess (this loop i already has scripted) is going on until is over.

The script is waiting for the first loop of 2min.

If the 2min are over, it will launch a new loop of 2min and the same mainprocess.

_2min loop starts

_mainprocess starts and end (the time is variable but not longer than 2min)

_2min are over and it starts the same 2min loop with mainprocess

You see my problem is that the time of the mainprocess is variable. (sleep function is useless)

I hope you can help me. (maybe with #AdlibEnable)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

loop21,

Welcome to the Autoit forum. ;)

You need an idle loop to fill in the time between the process ending and the 2min timer expiring. Here is a "proof of concept" script to show you how to do it:

; Provide an escape
HotKeySet("{ESC}", "On_Exit")
Func On_Exit()
    Exit
EndFunc

While 1

    $iBegin = TimerInit()

    ; Simulate main process
    Sleep(5000) ; This is only 5 seconds, but this is proof of concept!

    Do
        Sleep(10)
    Until TimerDiff($iBegin) > 10000 ; Again this is only 10 secs, but this is POC!

    ; Prove we wait 10 secs
    ConsoleWrite(@SEC & @CRLF)

WEnd

I hope that helps.

M23

Edit: Clarity

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks at first alot, that is what i want.

Now for 2min timer:

; Provide an escape
HotKeySet("{ESC}", "On_Exit")
Func On_Exit()
    Exit
EndFunc

While 1

    $iBegin = TimerInit()

    ; Simulate main process
    ; <--- 
           Sleep(5000) 
           ; This is only 5 seconds, but this is proof of concept! 
    ; <--- that's only a example for mainsequence

    Do
        Sleep(10)
    Until TimerDiff($iBegin) > 120000 ; Again this is only 120 secs (2min), but this is POC!

    ; Prove we wait 120 secs (2min)
    ConsoleWrite(@SEC & @CRLF)

WEnd

I hope that's Ok^^

Thanks for the fast reply!

Edited by loop21

Share this post


Link to post
Share on other sites

oh this is good it seems to be part of something I was thinking about, lets say we have a never ending while 1 = 1 code running is it possible to implement this timer outside of my main while loop to refresh my browser every lets say 5mins? I already have my code set to auto login etc but the problem is sometime the browser freezes and needs to be refreshed, even better how can I implement this inorder to do the following? if no clicks or mouse movement is taking place the timer will start to countdown from 30 seconds if there is movement the idle state is canceled but if the 30seconds are up without any movement then it will refresh the browser.. this is great lol ive only been at this reading tutorials and stuff and I already have lots of ideas to make my script full proof haha, my logic is all good but how to implement it is my only problem

Share this post


Link to post
Share on other sites

user101,

If you want to check on idle time, look at _Timer_GetIdleTime in the Help file. Using that in a loop will enable you to detect when you have gone a certain time without any keyboard or mouse activity.

M23

P.S. You are more likely to get help from the "less young" members around here if you were to capitalise and paragraph your post a little. We are not that used to "yoof-riting" and I for one found it quite hard to read. ;)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

user101,

If you want to check on idle time, look at _Timer_GetIdleTime in the Help file. Using that in a loop will enable you to detect when you have gone a certain time without any keyboard or mouse activity.

M23

P.S. You are more likely to get help from the "less young" members around here if you were to capitalise and paragraph your post a little. We are not that used to "yoof-riting" and I for one found it quite hard to read. :evil:

thank you so much ;) this is exactly what I needed

Share this post


Link to post
Share on other sites

Hello im from Germany and i hope my english will be enough good.

So i want to script a loop of 2minute.

That loop starts with the timer (can be hidden without msgbox or else), that timer begins to count.

After it starts the mainprocess (this loop i already has scripted) is going on until is over.

The script is waiting for the first loop of 2min.

If the 2min are over, it will launch a new loop of 2min and the same mainprocess.

_2min loop starts

_mainprocess starts and end (the time is variable but not longer than 2min)

_2min are over and it starts the same 2min loop with mainprocess

You see my problem is that the time of the mainprocess is variable. (sleep function is useless)

I hope you can help me. (maybe with #AdlibEnable)

I use this routine to exit at GUI Menu it will give you an idea how the timer works in this situation

#include <WindowsConstants.au3>


Global $EndMenuTime = 5000 ;//Set this variable for the elapese time
Global $sHelp = "[url="http://www.autoitscript.com/forum/"]http://www.autoitscript.com/forum/[/url]"

_DemoScript()

Func _DemoScript()
 While 1
  ;//Exit Menu After nn Minutes Nil Activity
  Local $MenuCycle = _TimeToTicks(@HOUR, @MIN, @SEC)
  Local $MenuEndCycle = $MenuCycle + $EndMenuTime
  ;//Paint the Panel
  GUICreate("Your Title", 340, 380, -1, -1)
  GUISetBkColor(0xE0FFFF)
  GUISetState()
  ;//Your User Input Code
  ;
  ;
  ;
  ;
  ;//Help
  $sEmailSmsHelp = GUICtrlCreateButton("Help", 175, 350, 65, 25)
  GUICtrlSetTip(-1, "Link to " & "Your Title" & " 'Help' [Internet Access Required] ", "Help", 1)
  GUICtrlSetColor(-1, 0x008040) ;Green
  ;//Close
  $Exit = GUICtrlCreateButton("Close", 255, 350, 65, 25)
  While 1
   ;//Exit after nn Minutes
   If _TimeToTicks(@HOUR, @MIN, @SEC) >= $MenuEndCycle Then
    GUIDelete()
    ExitLoop (2)
   EndIf
   ;//Read the Input Message
   $msg = GUIGetMsg()
   Select
    ;//Exit the Application
    Case $msg = $GUI_EVENT_CLOSE Or $msg = $Exit
     GUIDelete()
     ExitLoop (2)
    Case $msg = $sEmailSmsHelp
     GUIDelete()
     ShellExecuteWait($sHelp)
     ExitLoop
   EndSelect
  WEnd
 WEnd
EndFunc

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