Sign in to follow this  
Followers 0
Knucklehead

Repeating a Given Function For A Set Time

4 posts in this topic

First of all, Hello for anyone reading this.

I have been looking at the Help File and searching for a Pre-existing thread for a while now. I haven't found anything (doesn't mean it's not out there) I'm pretty tired and discouraged. I would like some help with this.

I would like to cause a Function to repeat itself for... oh let's say 12 minutes before terminating and moving on to the next part of the script.

AutoItSetOption("WinTitleMatchMode", 4)
Global $handle = WinGetHandle("classname=SoM3cRa2Yc0De")

WinWaitActive("Window Title")
                 
          
HotKeySet("{PGUP}", "Start")
HotKeySet("{F3}","Quit")

TogglePause()
                   
func Start() 
HotKeySet("{PGUP}")
HotKeySet("{PGUP}", "TogglePause")
ToolTip('Stuff is Happening',0,0)

ControlSend($handle, "", "", "") ;This is what I would like to repeat for 12 minutes
Sleep("somenumber")
ControlSend($handle, "", "", "")
Sleep("somenumber") ;This is the end

EndFunc

Func TogglePause()
ToolTip('Stuff is Not Happening',0,0)
HotKeySet("{PGUP}")
HotKeySet("{PGUP}", "Start")
While 1
sleep(100)
WEnd
EndFunc

func Quit()
HotKeySet("{F3}"
Exit
EndFunc

This is a basic example script to maybe show you what I mean and give you something to tinker with, as well as making this easier for me to relate to and implement in the future.

Cheers

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Func Start()
    Local $iInit
    
    HotKeySet("{PGUP}")
    HotKeySet("{PGUP}", "TogglePause")
    ToolTip('Stuff is Happening',0,0)

    $iInit = TimerInit()
    
    Do
        ControlSend($handle, "", "", "") ;This is what I would like to repeat for 12 minutes
        Sleep(150) ; somenumber
    Until (TimerDiff($iInit)/60000) > 12 ; 12 minutes
    
    $iInit = TimerInit()
    
    Do
        ControlSend($handle, "", "", "")
        Sleep(150) ; This is the end
    Until (TimerDiff($iInit)/1000) > 30 ; 30 seconds
EndFunc

Edited by Authenticity

Share this post


Link to post
Share on other sites

Clever! I looked up the Timer functions AND the Do...Until Loop. I never thought to put them together...

Thanks, I'll test it tomorrow. Sleep("tonight") lol

Brilliant... ;)

Share this post


Link to post
Share on other sites

Everything is ran smooth! Thank you. I really can't get over how clever that was o.0

So much to do with this Scripting Language...

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