Jump to content

2 loops repeat constantly


Recommended Posts

Hi,

I have code (mouse clicks and sending keys) that do stuff till i stop the script.

Like:

HotKeySet("{ESC}", "Terminate")
While 1
DO STUFF
WEnd
Func Terminate()
    Exit 0
EndFunc

but i would like to add one more step into to this loop/script.

It would make below "Do STUFF"

HotKeySet("{ESC}", "Terminate")
While 1
DO STUFF
WEnd
Func Terminate()
    Exit 0
EndFunc

for example: 10 times

and then do "One STUFF" only once.

So in final "DO STUFF" goes 10times and "One STUFF" goes 1time.

And i would like to loop it so in the end we have script that will be going and going till i press "ESC" (and scrips will be doing two things, one 10times and second 1time).

 

Hope i explain what i want to achieve clearly :)

Thank you in advance for help!

Link to comment
Share on other sites

9 hours ago, Kotinho07 said:

Hope i explain what i want to achieve clearly :)

Do you mean something like this :

HotKeySet("{ESC}", "Terminate")
Local Const $MAXCOUNT = 10 ; 10 times
Local $iCounter = 1
While True
    Sleep(500) ; Just to make the console output viewable (otherwise 50)
    If $iCounter <= $MAXCOUNT Then
        ConsoleWrite(StringFormat("Do 'STUFF' %02i out of 10 times", $iCounter) & @CRLF)
        $iCounter += 1
    Else
        ConsoleWrite("Do 'OTHER STUFF' one time" & @CRLF)
        $iCounter = 1
        ConsoleWrite("==> RESTART" & @CRLF)
    EndIf
WEnd

Func Terminate()
    ConsoleWrite("Ecit Programm" & @CRLF)
    Exit 0
EndFunc

EDIT : Here is a variant with For..Next. There are a several ways to skin this cat ;).

HotKeySet("{ESC}", "Terminate")
While True
    Sleep(500) ; *** just to make the console output viewable
    For $i = 1 To 10 Step 1
        Sleep(500) ; *** just to make the console output viewable
        ConsoleWrite(StringFormat("+ Do 'STUFF' here %02i out of 10 times", $i) & @CRLF)
    Next
    ConsoleWrite("> Do 'OTHER STUFF' here one time" & @CRLF)
WEnd
Func Terminate()
    Exit 0
EndFunc

 

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

  • 2 weeks later...

 

7 hours ago, Kotinho07 said:

Hi, ok, but why my loop do not want to go after next?

Spoiler
HotKeySet("{ESC}", "Terminate")
While True

For $i = 1 To 3 Step 1

MouseClick("left", 1628, 1251, 1, 20)

Next
    
MouseClick("left", 50, 248, 1, 20)
WEnd
Func Terminate()


Exit 0
EndFunc

 

As @JockoDundee already suggested : Add e.g. some ConsoleWrites to follow the process.

HotKeySet("{ESC}", "Terminate")

Local $iX, $iY ; *** the x/y coordinates to move the mouse to
Local $iWhileLoopCounter = 1

While True
    ConsoleWrite(StringFormat("+ ==> WHILE LOOP : %04i", $iWhileLoopCounter) & @CRLF)

    $iX = 1628
    $iY = 1251
    Sleep(500) ; *** just to make the console output viewable
    For $i = 1 To 3 Step 1
        ConsoleWrite("> --> FOR..NEXT : " & $i & " out of 3 times ")
        Sleep(100) ; *** just to make the console output viewable
;~      MouseClick("left", $iX, $iY, 1, 20)
        ConsoleWrite(StringFormat("> ------>  MouseClick on X=%04i  Y=%04i", $iX, $iY) & @CRLF)
    Next

    $iX = 50
    $iY = 248
    Sleep(500)
;~  MouseClick("left", $iX, $iY, 1, 20)
    ConsoleWrite(StringFormat("< -->  MouseClick on X=%04i  Y=%04i", $iX, $iY) & @CRLF)

    $iWhileLoopCounter += 1
WEnd

Func Terminate()
    Exit 0
EndFunc
Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

I have some more mouse clicks in two loops. I will put two lines as example.

HotKeySet("{ESC}", "Terminate")
#include <MsgBoxConstants.au3>

While True
Sleep(500)
    For $i = 1 To 1 Step 1
Sleep(500)
ConsoleWrite(StringFormat(
MouseClick("left", 1628, 1251, 1, 20)
MouseClick("left", 1504, 363, 1, 20)
Send("{ENTER}")
Sleep ( 3000 )
, $i) & @CRLF)

MsgBox($MB_SYSTEMMODAL, "Check", "Check", 10)
    
    Next
ConsoleWrite(
MouseClick("left", 50, 248, 1, 20)
MouseClick("left", 1322, 325, 1, 20)
& @CRLF)

WEnd
Func Terminate()
    Exit 0
EndFunc

I have put message box but it do not show up. I see buy the mouse moment that it goes only in one loop and do not skip to next.

Thank you for you help in advance.

Link to comment
Share on other sites

2 hours ago, Kotinho07 said:

I have some more mouse clicks in two loops. I will put two lines as example.

It is possible to concatenate e.g. variable assignments and function parameters over several lines ( see Underscore).

For reasons of clarity, however, I would recommend, especially for beginners, to output separate ConsoleWrites.

HotKeySet("{ESC}", "Terminate")

Local $iWhileLoopCounter = 1
While True
    ConsoleWrite(StringFormat('+ ==> WHILE LOOP : %04i', $iWhileLoopCounter) & @CRLF)

    Sleep(500) ; *** just to make the console output viewable
    For $i = 1 To 3 Step 1
        ConsoleWrite('> --> FOR..NEXT : ' & $i & ' out of 3 times ' & @CRLF)
        Sleep(150) ; *** just to make the console output viewable

        ; Commands :
;~      MouseClick("left", 1628, 1251, 1, 20)
        ConsoleWrite(StringFormat('> ------>  MouseClick on X=%04i  Y=%04i', 1628, 1251) & @CRLF)

;~      MouseClick("left", 1504, 363, 1, 20)
        ConsoleWrite(StringFormat('> ------>  MouseClick on X=%04i  Y=%04i', 1504, 363) & @CRLF)

;~      Send("{ENTER}")
        ConsoleWrite('> ------>  Send ({"ENTER"})' & @CRLF)
        ConsoleWrite('>          ----------------------------------------------- ' & @CRLF)

        ; [...]

    Next

    Sleep(500)

;~  MouseClick("left", 50, 248, 1, 20)
    ConsoleWrite(StringFormat('< -->  MouseClick on X=%04i  Y=%04i', 50, 248) & @CRLF)

;~  MouseClick("left", 1322, 325, 1, 20)
    ConsoleWrite(StringFormat('< -->  MouseClick on X=%04i  Y=%04i', 1322, 325) & @CRLF)

    $iWhileLoopCounter += 1
WEnd

Func Terminate()
    Exit 0
EndFunc

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

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