danielmohr91 Posted October 1, 2009 Share Posted October 1, 2009 Hi, I'm just started using AutoIt this past week. I've been learning the basics of variables and "Do, Until" loops. I need to slow my mouse speed way down. I tried AutoItSetOption("mouseclickdelay",2000) but it only works for the first click I've resorted to $speed = InputBox("Speed","type in speed","2000") and pasting sleep($sleep) after every single click. It works, but is prohibitively time consuming. Is there a way around this? Here's an example of what I meanexpandcollapse popupMouseMove(898,692) Sleep($speed) MouseDown("left") MouseUp("left") MouseMove(582,489) Sleep($speed) MouseDown("left") MouseUp("left") MouseMove(471,580) Sleep($speed) MouseDown("left") MouseUp("left") MouseMove(683,444) Sleep($speed) MouseDown("left") MouseUp("left") MouseMove(472,579) Sleep($speed) MouseDown("left") MouseUp("left") MouseMove(480,449) Sleep($speed) Sleep($speed) MouseDown("left") MouseUp("left") MouseMove(470,582) Sleep($speed) MouseDown("left") MouseUp("left") MouseMove(581,396) Sleep($speed/2) Sleep($speed) MouseDown("left") MouseUp("left") MouseMove(475,577) Sleep($speed) MouseDown("left") MouseUp("left") MouseMove(847,693) Sleep($speed) MouseDown("left") MouseUp("left") MouseMove(848,635) Sleep($speed/2) MouseDown("left") MouseUp("left") MouseMove(590,541) Sleep($speed/2) etc... the /2 is to make those particular clicks half the wait. That code goes on and on. Is there a way to quickly add some sort of global speed setting? Link to comment Share on other sites More sharing options...
Hawkwing Posted October 1, 2009 Share Posted October 1, 2009 I think it would be easier to do something like this. Dim $array[3][2] $sleep = 2000 $array[0][0] = 1 $array[0][1] = 1 $array[1][0] = 50 $array[1][1] = 120 $array[2][0] = 504 $array[2][1] = 152 For $i = 0 To UBound($array) - 1 MouseClick("left", $array[$i][0], $array[$i][1], 1, 0) Sleep($sleep) Next The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
danielmohr91 Posted October 5, 2009 Author Share Posted October 5, 2009 I think it would be easier to do something like this. Dim $array[3][2] $sleep = 2000 $array[0][0] = 1 $array[0][1] = 1 $array[1][0] = 50 $array[1][1] = 120 $array[2][0] = 504 $array[2][1] = 152 For $i = 0 To UBound($array) - 1 MouseClick("left", $array[$i][0], $array[$i][1], 1, 0) Sleep($sleep) Next Whoah. I read the help files about Dim and Array. I don't get what you mean. Did you define the 6 constant variables and use those as the mouse coordinates? I'm new to all of this. I don't understand what that has to do with the delay. Could you briefly explain what that means? Link to comment Share on other sites More sharing options...
Hawkwing Posted October 6, 2009 Share Posted October 6, 2009 I just put a few places I wanted to click at in the array. 1,1 50,120 and 504,152. Then the For loop loops through the entire array clicking each place and sleeping 2 seconds because I had $sleep = 2000. Perhaps you'll understand it better if you add "#include<array.au3>" to the top and "_ArrayDisplay($array)" at the bottom. One thing that you sometimes have to remember when displaying arrays is that rather than being x,y they are y,x. So $array[3][5] is really the 3rd row and 5th column of $array. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
omikron48 Posted October 6, 2009 Share Posted October 6, 2009 (edited) What you could do is just define your own function that includes the Sleep call after every mouse click you do. I did it to avoid code bloat when I recoded my installation scripts to use WinActivate and such, for every ControlClick and Send. Something like: Global $sleep = 2000 Func _MouseClick($button, $x, $y, $delay = $sleep) MouseClick($button, $x, $y) Sleep($delay) EndFunc The way the function is declared, it will use the value of $sleep by default unless a third parameter is provided. Also, since you just use MouseDown and MouseUp in succession without code in between, it's better to just use MouseClick. To use, just do one of the following: _MouseClick("left", 470,582) ;$delay used is 2000 (from $sleep) _MouseClick("left", 590,541, $sleep / 2) Edit: MouseClick automatically moves the mouse to the specified (x,y) coordinates and does a mouse click using the specified mouse button. You can check the help file for more information about it. Edited October 6, 2009 by omikron48 Link to comment Share on other sites More sharing options...
Hawkwing Posted October 6, 2009 Share Posted October 6, 2009 Yes, that would work, but it would be just about as time consuming as adding Sleep($sleep) after each click. With an array he can just do something like this. If $i = 2 Or 5 Or 99 Then Sleep($sleep / 2) Else Sleep($sleep) EndIf He would still have to find out which times he wanted to do $sleep/2, but it seems a whole lot less time consuming. Not to put you down or anything, but I just think my way is a whole lot better The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
omikron48 Posted October 6, 2009 Share Posted October 6, 2009 Well, a function would be more convenient if you plan to do mouse clicks with delay at different portions of your script. It's not practical to stick a loop and array declaration every time you need delayed mouse clicks. Nor is it practical to stick a long Or condition for the instances you need ($sleep / 2). That would only slow down your script by running a long boolean evaluation every time you enter your loop. Just imagine if he needs to do a hundred or more mouse clicks with delay variations dispersed throughout. That would be a nightmare. Link to comment Share on other sites More sharing options...
Hawkwing Posted October 6, 2009 Share Posted October 6, 2009 You know, I actually made a nice easy little mouseclick recorder once. You could just click while holding alt and it would record it, and then you could save the array to a file. I was actually thinking about updating it somehow so you could have a 3rd column of sleep values so you didn't have to sleep the same in between mouseclicks when you used it with autoit. I'll see if I can go find it and update it real quick. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
Hawkwing Posted October 6, 2009 Share Posted October 6, 2009 Wow, I ended up redoing most of it. Kinda strange to go back and look at a script you made around the time you just found out about autoit. Here's the one to capture mouseclicks, and I added in a way to change the sleep value. HotKeySet("!c", "capture") HotKeySet("!^c", "capturewithtime") $savelocation = FileSaveDialog("Save Location", @ScriptDir, "Text Files (*.txt)", 16) $delimiter = InputBox("Delimiter", "Type what you want to go between x, y, and sleep values.", ",") $time = InputBox("Time", "Type what you want the default sleep time to be.", 1000) While 1 Sleep(1000) WEnd Func capture() Send("{altup}") $temppos = MouseGetPos() FileWrite($savelocation, $temppos[0] & $delimiter & $temppos[1] & $delimiter & $time & @CRLF) EndFunc Func capturewithtime() Send("{altup}{ctrlup}") $temppos = MouseGetPos() $temptime = InputBox("Time", "Type what you want the sleep time to be for after this click.", $time) FileWrite($savelocation, $temppos[0] & "," & $temppos[1] & $delimiter & $temptime & @CRLF) EndFunc And here's the one to execute those mouseclicks. HotKeySet("!c", "capture") HotKeySet("!^c", "capturewithtime") $savelocation = FileSaveDialog("Save Location", @ScriptDir, "Text Files (*.txt)", 16) $delimiter = InputBox("Delimiter", "Type what you want to go between x, y, and sleep values.", ",") $time = InputBox("Time", "Type what you want the default sleep time to be.", 1000) While 1 Sleep(1000) WEnd Func capture() Send("{altup}") $temppos = MouseGetPos() FileWrite($savelocation, $temppos[0] & $delimiter & $temppos[1] & $delimiter & $time & @CRLF) EndFunc Func capturewithtime() Send("{altup}{ctrlup}") $temppos = MouseGetPos() $temptime = InputBox("Time", "Type what you want the sleep time to be for after this click.", $time) FileWrite($savelocation, $temppos[0] & "," & $temppos[1] & $delimiter & $temptime & @CRLF) EndFunc Shouldn't be too hard too add in right/left clicking if you want too. Much easier than listing a whole bunch of mouseclick coords. Even if you already have a bunch of them, it wouldn't be to hard to format them so that they would work with this. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
danielmohr91 Posted October 17, 2009 Author Share Posted October 17, 2009 Wow, I ended up redoing most of it. Kinda strange to go back and look at a script you made around the time you just found out about autoit. Here's the one to capture mouseclicks, and I added in a way to change the sleep value. HotKeySet("!c", "capture") HotKeySet("!^c", "capturewithtime") $savelocation = FileSaveDialog("Save Location", @ScriptDir, "Text Files (*.txt)", 16) $delimiter = InputBox("Delimiter", "Type what you want to go between x, y, and sleep values.", ",") $time = InputBox("Time", "Type what you want the default sleep time to be.", 1000) While 1 Sleep(1000) WEnd Func capture() Send("{altup}") $temppos = MouseGetPos() FileWrite($savelocation, $temppos[0] & $delimiter & $temppos[1] & $delimiter & $time & @CRLF) EndFunc Func capturewithtime() Send("{altup}{ctrlup}") $temppos = MouseGetPos() $temptime = InputBox("Time", "Type what you want the sleep time to be for after this click.", $time) FileWrite($savelocation, $temppos[0] & "," & $temppos[1] & $delimiter & $temptime & @CRLF) EndFunc And here's the one to execute those mouseclicks. HotKeySet("!c", "capture") HotKeySet("!^c", "capturewithtime") $savelocation = FileSaveDialog("Save Location", @ScriptDir, "Text Files (*.txt)", 16) $delimiter = InputBox("Delimiter", "Type what you want to go between x, y, and sleep values.", ",") $time = InputBox("Time", "Type what you want the default sleep time to be.", 1000) While 1 Sleep(1000) WEnd Func capture() Send("{altup}") $temppos = MouseGetPos() FileWrite($savelocation, $temppos[0] & $delimiter & $temppos[1] & $delimiter & $time & @CRLF) EndFunc Func capturewithtime() Send("{altup}{ctrlup}") $temppos = MouseGetPos() $temptime = InputBox("Time", "Type what you want the sleep time to be for after this click.", $time) FileWrite($savelocation, $temppos[0] & "," & $temppos[1] & $delimiter & $temptime & @CRLF) EndFunc Shouldn't be too hard too add in right/left clicking if you want too. Much easier than listing a whole bunch of mouseclick coords. Even if you already have a bunch of them, it wouldn't be to hard to format them so that they would work with this. Well thank you so much for the replies everyone. I've been absolutely swamped with all this college homework so I havn't gotten to work on this as much as I would like. Hawkwing -- Thank you ever so much for the recorder. I records great, but I couldn't quite figure out how to play it back. I copied the coordinates from the text file into a new autoit script but I would have had to paste "MouseClick," In front of every line. I wouldn't mind doing his for every script, it's easier than skipping every three lines and pasting $sleep how I was originally, but it sounds like you have an easier way of playing it back with the second script you listed. Could you enlighten me? I also tried adding a new variable to the recording script that literally added "MouseClick," at the end of each line, but it was just regular text (not navy blue) when pasted into autoit and gave me an error that I didn't understand. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now