Jump to content
Sign in to follow this  
pikablue

While Loop Help (I don't get it)

Recommended Posts

pikablue

Hello, I am very new to the autoit, I always wants to create some kind of scrip to automatically operate my computer without me being on it. Like moving mouse on its own, click, send keys etc. I've searched through the forum and looked into while, do, and for Loop functions. But I don't understand it at all. I know that with While Loop, You need a condition for it to keep looping, how do I set the condition to be every 40 minutes? I want it to loop a set of mouse movements on its own every 40 minutes. Also is it possible for me to disable this loop with a hotkey?

AutoItSetOption("MouseClickDelay", 100)
AutoItSetOption("MouseClickDownDelay", 100)
MouseClick("Left", 300, 790, 2)
MouseClick("Left", 400, 650, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 790, 350, 2)
Edited by pikablue

Share this post


Link to post
Share on other sites
Authenticity

Use AdlibEnable instead or better schedule your compiled AutoIt script to execute every 40 minutes (daily, monthly, forever, etc..).

If you just want to use it in a loop just make an inner loop to sleep and increase a counter stating the minutes passed since it's began running and terminate it if the counter is 40 and you'll fall back to the outer loop. Something As followed:

Global $iCounter
Global $fLoop = True

HotKeySet{'{ESC}', 'Close')

While $fLoop
    ; Do Stuff here
        $iCounter = 0
        While $fLoop
        $iCounter += 1
        Sleep(1000)
        If $iCounter = 40 Then ExitLoop
    WEnd
WEnd

Func Close()
    $fLoop = False
    ; Or Exit
EndFunc

Share this post


Link to post
Share on other sites
pikablue

Thank you so much for the quick reply, but would you please explain more detail in how this loop works? and what is AdlibEnable you just mentioned? Like break down of each small sections and put them in english lol sorry

Global $iCounter
Global $fLoop = True

HotKeySet{'{ESC}', 'Close')

While $fLoop
AutoItSetOption("MouseClickDelay", 100)
AutoItSetOption("MouseClickDownDelay", 100)
MouseClick("Left", 300, 790, 2)
MouseClick("Left", 400, 650, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 790, 350, 2)
$iCounter = 0
        While $fLoop
        $iCounter += 1
        Sleep(1000)
        If $iCounter = 40 Then ExitLoop
    WEnd
WEnd

Func Close()
    $fLoop = False
   ; Or Exit
EndFunc

So is it like this? but I'm getting an error says HotKeySet{'{ESC}', 'Close') is missing separator character after keyword

Edited by pikablue

Share this post


Link to post
Share on other sites
Authenticity

Read the help file, it's better and faster with a few grate example in almost every documented function in the bottom of it's description.

While <expression>
    statements
    ...
WEnd

The <expression> clause is get checked and interpreted to either false or true before each iteration.

Edit: Sorry, my mistake. It's HotKeySet('{ESC}', 'Close') with an opening round parentheses.

Edited by Authenticity

Share this post


Link to post
Share on other sites
pikablue

thanks a bunch, i figure some stuff out. here's what i got:

Global $iCounter
Global $fLoop = True

HotkeySet("{Esc}", "Close")
While $fLoop
AutoItSetOption("MouseClickDelay", 100)
MouseClick("Left", 300, 790, 2)
MouseClick("Left", 400, 650, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
MouseClick("left", 450, 475, 2)
MouseClick("left", 475, 350, 2)
AutoItSetOption("MouseClickDownDelay", 100)
MouseClick("left", 790, 350, 2)
$iCounter = 40
        While $fLoop
        $iCounter -= 1
        MsgBox(0, "", "Minutes left: " & $iCounter, 1)
        Sleep(1000*59)
        If $iCounter = 0 Then ExitLoop
    WEnd
WEnd

Func Close()
    $fLoop = False
  ; Or Exit
EndFunc

Hows that ^^. BTW the Esc key works great, except I need to wait til the auto it finishes it's current job, is there anyway for it to terminate autoit forcefully?

Edited by pikablue

Share this post


Link to post
Share on other sites
bo8ster

Use Exit.I use:

Func MyExit()
    ConsoleWrite("Script Stoppted by user")
    Exit
EndFunc   ;==>MyExit

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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  

×