Jump to content

Trying to get the hang of it


Guest OldandSlow
 Share

Recommended Posts

Guest OldandSlow

Ok here it goes... I have just started messing around with AutoIt. It is a very interesting program with a lot of uses I am seeing. In my attempting to learn about how to use it I started a simple project for me or so I thought. Basically what I wanted to do was be able to move the mouse cursor to a certain position in a window and click several times. Not a problem I can use the AU3Recorder to generate the code for this script. After doing so I started thinking there has to be a way to make it so I dont have a collection of 25 of these lines:

MouseMove(509,319)

MouseDown("right")

MouseUp("right")

Sleep(1000)

So I go to the help file and look at loop statements. Things get real sketchy here.

I am not sure how to use or which statement to use. I want to basically do the above statement 25 times. I know that I need to set a variable in there some where and then use a loop statement but all of the things I have tried have ended up not working. If someone could give a newb a point in the right direection it would be much appreciated.

Thanks in advance

OldandSlow

Edited by OldandSlow
Link to comment
Share on other sites

$i = 1
While $i <= 25
    MouseDown("right")
    MouseUp("right")
    Sleep(1000)
    $i = $i + 1
WEnd

<{POST_SNAPBACK}>

; For/Next example

For $i = 1 to 25 step 1
    MouseDown("right")
    MouseUp("right")
    Sleep(1000)
Next

; Do/Until example
$i = 1
Do
    MouseDown("right")
    MouseUp("right")
    Sleep(1000)
    $i = $i + 1
Until $i >= 25

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Guest OldandSlow

hehe that helped immensely now I see how the you can loop the mouse clicks. I tried making this little excersize an infinite loop until I used a pause or an escape button but failed miserably at my attempts. Adding to the mess I have created, I added a send in the mix.

I am curious, and have yet to figure out why in this bit of code the f9 key is pressed after every right click. I guess I am trying to make the mouse click 19 times and after the 19th time send the f9 key. I know it is something simple but I am still scratching my head.

While $i <= 19

MouseMove(509,302)

MouseDown("right")

MouseUp("right")

Sleep(4000)

$i = $i + 1

Send("{F9}","")

WEnd

I also went and did a stupid thing and made an infinite loop out of this and couldnt turn it off without shutting things down. I am still trying to figure out the hotkey thing so I can pause or terminate the script. Anyways thanks for pointing me in the right direction for the loop statements.

OldandSlow

Link to comment
Share on other sites

You have the Send("{F9}") in the loop take it out of the loop and it will do it after the 19th is clicked.

Edit: Also to exit out of the script, you could have just right clicked on the AutoIt icon in the bottom right hand tray and selected exit.

Edited by automagician
Link to comment
Share on other sites

Guest OldandSlow

Yes I moved the send key out of the loop and it works. I guess I am not explaining myself very well. I would like this script to right click 19 times and then hit the f9 key and then repeat the process over and over again. I have been reading on the hotkeyset and I think I am getting a grasp of it to turn off or pause the whole mess.

Link to comment
Share on other sites

Guest OldandSlow

Basically I have been flipping back and forth through the forum and the help file. Looking at scripts people have written to get an idea of how things should look for whatever it is I am trying to do. Mine eyes are buggy so it is time to give it a rest. Thanks a lot for your help Auto I will go rest now hehe.

OldandSlow

Link to comment
Share on other sites

Basically I have been flipping back and forth through the forum and the help file. Looking at scripts people have written to get an idea of how things should look for whatever it is I am trying to do. Mine eyes are buggy so it is time to give it a rest. Thanks a lot for your help Auto I will go rest now hehe.

OldandSlow

<{POST_SNAPBACK}>

Ok, this script is very close to what you described a couple of posts back.

Infinate loop until Ctrl+C is pressed.

Right clicks in the active window 19 times then sends an F9

It uses what's called a "Nested While Loop" and a User Defined Function (UDF).

HotKeySet("^C","MyExit")

While 1
   $i = 1
   While $i < 20
    ; Do mouse Clicking functions
    ; Hint, look up this function:  Mouseclick()
    ; Mouseclick("mouse button",x,y,clicks,speed)
      Mouseclick("right",50,50,1,0)
      $i = $i + 1
    Wend
    Send("{F9}")
WEnd

Func MyExit()
   Exit
EndFunc

Loops and Functions (user defined or built-in) are the "meat and potatoes" of this language. Most everything (especially in a GUI) happens in one form of a loop or another, and every "command" is actually a "function"

We welcome you to the community and hope you enjoy your time!

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

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