Jump to content

Always checking "If" and Script GoTo Beginning


Recommended Posts

Hello.

Only today I found out about ScriptIT and found it to be a wonderful program. Before I used a program "Advanced Keyboard and Mouse Macro Maker", but I find that this is much, much better.

My experience with programming though is at beginners level, so I need a little help with my script.

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


WinActivate("myWindow1")

Do ;loop start



Send(" {F5} ")
Sleep(3000)
MouseWheel( "Up" , 20)

MouseClick("left", 1380, 29, 1, 0)
Sleep(1500)


    MouseClickDrag("left", 281, 407, 238, 158, 0)
    MouseClickDrag("left", 486, 394, 375, 146, 0)
    MouseClickDrag("left", 698, 394, 691, 148, 0)
    MouseClickDrag("left", 901, 397, 842, 163, 0)
    MouseClickDrag("left", 1111, 390, 1001, 149, 0)
    MouseClickDrag("left", 1314, 402, 1149, 153, 0)
    MouseClickDrag("left", 293, 591, 232, 138, 0)
    MouseClickDrag("left", 499, 614, 380, 166, 0)
    MouseClickDrag("left", 697, 612, 531, 170, 0)
    MouseClickDrag("left", 910, 599, 848, 142, 0)
    MouseClickDrag("left", 1108, 603, 994, 150, 0)
    MouseClickDrag("left", 1320, 559, 1160, 157, 0)
    MouseClickDrag("left", 280, 801, 385, 138, 0)
    MouseClickDrag("left", 498, 811, 388, 154, 0)
    MouseClickDrag("left", 705, 813, 539, 147, 0)
    MouseClickDrag("left", 897, 794, 683, 133, 0)
    MouseClickDrag("left", 1107, 808, 841, 142, 0)


If WinExists("AlertHand1e1") Then
    WinClose("AlertHandle1")
EndIf





Until False ;loop end

Func MyExit()
    Exit
EndFunc

What I need help with is this part

If WinExists("AlertHand1e1") Then
    WinClose("AlertHandle1")
EndIf

First of all, I need AutoIT to check for this IF event ALL THE TIME while the script is running. How would I do that?

Second of all, after WinClose, I need it to go to the beginning of my loop and start over. I read that "GoTo" function has been taken out in v3.

Thank you for listening.

P.S. I got another problem I forgot to mention. I don't have any idea why, but the script sometimes at the end or beginning of it, drags my scrollable window (where the scrip is/should be working in) all the way down. I tried to insert some "Send(" {HOME} "), but all it did was scroll the window all the way up where I wanted it for a milisecond and drags it all the way down again (in an instant), though sometimes it would stay at the top. "MouseWheel( "Up" , 20)" seems to work, but it's a laggy and shitty solution.

Edited by TropicThunder
Link to comment
Share on other sites

In short, what my script does is drag some items in a webpage from one place to another. Do not ask where I use it or why, but it's a monotonous job and tiring when done manually.

Sorry, but I have to ask. The reason is you said the window is a web page. There may be a much easier way to do what you have in mind but knowing the page would help. If for example you are working with excel that is embedded in a web page, then there are commands to make your job simple.

Edited by Melba23
Amended quoted username to match current username following user's request
Link to comment
Share on other sites

@1: by "ALL THE TIME" I presume you mean that because of the Sleep() statements the window in question is not closed quickly enough for your taste? I see two easy solutions:

a. use AdlibRegister ( "function" [, time] ) to make your script execute a certain function every so-and-so-many msec...

b. and/or don't use sleep but let your loop run continuously and use TimerInit() and TimerDiff() to check how much msec has passed

@2: not exactly clear what you mean, but the Continue command skips to the next loop iteration immediately. Ofcourse if you use Sleep(), the script just halts, so all the more reason to use both options above to avoid using Sleep(). You could try having your loop look for some global variabele set to True (by the window checking adlib function) and if it is true, set it to false again and execute Continue and the whole thing starts over...

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

@1: by "ALL THE TIME" I presume you mean that because of the Sleep() statements the window in question is not closed quickly enough for your taste? I see two easy solutions:

a. use AdlibRegister ( "function" [, time] ) to make your script execute a certain function every so-and-so-many msec...

b. and/or don't use sleep but let your loop run continuously and use TimerInit() and TimerDiff() to check how much msec has passed

@2: not exactly clear what you mean, but the Continue command skips to the next loop iteration immediately. Ofcourse if you use Sleep(), the script just halts, so all the more reason to use both options above to avoid using Sleep(). You could try having your loop look for some global variabele set to True (by the window checking adlib function) and if it is true, set it to false again and execute Continue and the whole thing starts over...

By "All the time" I meant during all those drag&drop operations (everything inside the loop). Currently my script only checks for the Alert popup box only at the end of these operations (end of all those MouseClickDrag(), but before loop ends), but I need him to check after EVERY operation the script have done. The Sleep() statements only are there so the script would wait before certain images and elements in the page are loaded. They are not there to close any windows.

I've tried using AdlibRegister to check for those Alert boxes, but it doesn't seem to work at all.

Please see if I did something wrong, or maybe you have another idea how to achieve what I need?

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


WinActivate("Mozilla Firefox")

Func Alert1()
If WinExists("Alert1") Then
    WinClose("Alert1")
    Send(" {F5} ")
    Sleep(1500)
EndIf
EndFunc

Do ;loop start

    AdlibRegister(Alert1(), 500)

Send(" {F5} ")
Sleep(3000)
MouseWheel( "Up" , 20)

MouseClick("left", 1380, 29, 1, 0)
Sleep(1500)


    MouseClickDrag("left", 281, 407, 238, 158, 0)
    MouseClickDrag("left", 486, 394, 375, 146, 0)
    MouseClickDrag("left", 698, 394, 691, 148, 0)
    MouseClickDrag("left", 901, 397, 842, 163, 0)
    MouseClickDrag("left", 1111, 390, 1001, 149, 0)
    MouseClickDrag("left", 1314, 402, 1149, 153, 0)
    MouseClickDrag("left", 293, 591, 232, 138, 0)
    MouseClickDrag("left", 499, 614, 380, 166, 0)
    MouseClickDrag("left", 697, 612, 531, 170, 0)
    MouseClickDrag("left", 910, 599, 848, 142, 0)
    MouseClickDrag("left", 1108, 603, 994, 150, 0)
    MouseClickDrag("left", 1320, 559, 1160, 157, 0)
    MouseClickDrag("left", 280, 801, 385, 138, 0)
    MouseClickDrag("left", 498, 811, 388, 154, 0)
    MouseClickDrag("left", 705, 813, 539, 147, 0)
    MouseClickDrag("left", 897, 794, 683, 133, 0)
    MouseClickDrag("left", 1107, 808, 841, 142, 0)


Until False ;loop end

Func MyExit()
    Exit
EndFunc
Edited by TropicThunder
Link to comment
Share on other sites

So, I figured out how to properly use AdlibRegister function and now it's always checking for Alert boxes and automatically closes them. The only problem that remains is, after he closes those Alert boxes, he continues the script. I need him to Restart at the beginning of the LOOP part of my script after the Alert box has been closed.

 

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


WinActivate("Mozilla Firefox")



Do ;loop start

;<==== I NEED TO RESTART THE SCRIPT HERE AFTER function "Alert" HAS DONE IT'S JOB

AdlibRegister("Alert", 100)




Send(" {F5} ")
Sleep(3000)
MouseWheel( "Up" , 20)

MouseClick("left", 1380, 29, 1, 0)
Sleep(1500)


    MouseClickDrag("left", 281, 407, 238, 158, 0)
    MouseClickDrag("left", 486, 394, 375, 146, 0)
    MouseClickDrag("left", 698, 394, 691, 148, 0)
    MouseClickDrag("left", 901, 397, 842, 163, 0)
    MouseClickDrag("left", 1111, 390, 1001, 149, 0)
    MouseClickDrag("left", 1314, 402, 1149, 153, 0)
    MouseClickDrag("left", 293, 591, 232, 138, 0)
    MouseClickDrag("left", 499, 614, 380, 166, 0)
    MouseClickDrag("left", 697, 612, 531, 170, 0)
    MouseClickDrag("left", 910, 599, 848, 142, 0)
    MouseClickDrag("left", 1108, 603, 994, 150, 0)
    MouseClickDrag("left", 1320, 559, 1160, 157, 0)
    MouseClickDrag("left", 280, 801, 385, 138, 0)
    MouseClickDrag("left", 498, 811, 388, 154, 0)
    MouseClickDrag("left", 705, 813, 539, 147, 0)
    MouseClickDrag("left", 897, 794, 683, 133, 0)
    MouseClickDrag("left", 1107, 808, 841, 142, 0)


Until False ;loop end

Func Alert()
If WinExists("Alertbox") Then
    WinClose("Alertbox")
EndIf
EndFunc



Func MyExit()
    Exit
EndFunc
Edited by Melba23
Amended username to match current username following user's request
Link to comment
Share on other sites

Maybe something like this? (Untested...) Oh and put your adlib outside of the loop :graduated:

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

WinActivate("Mozilla Firefox")

AdlibRegister("Alert", 100)

Do ;loop start
    ;<==== I NEED TO RESTART THE SCRIPT HERE AFTER function "Alert" HAS DONE IT'S JOB
    $needToRestartLoop = False

    Send(" {F5} ")
    specialSleep(3000)
    If $needToRestartLoop Then ContinueLoop

    MouseWheel("Up", 20)

    MouseClick("left", 1380, 29, 1, 0)
    specialSleep(1500)
    If $needToRestartLoop Then ContinueLoop

    MouseClickDrag("left", 281, 407, 238, 158, 0)
    ; blah

Until False ;loop end

Func Alert()
    If WinExists("Alertbox") Then
        WinClose("Alertbox")
        $needToRestartLoop = True
    EndIf
EndFunc   ;==>Alert

Func specialSleep($msecToWait)
    $stamp = TimerInit()
    While $needToRestartLoop = False And TimerDiff($stamp) < $msecToWait
        Sleep(10)
    WEnd
EndFunc   ;==>specialSleep

Func MyExit()
    Exit
EndFunc   ;==>MyExit

Roses are FF0000, violets are 0000FF... All my base are belong to you.

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