demandnothing Posted April 13, 2010 Share Posted April 13, 2010 (edited) This is my script. expandcollapse popupGlobal $StopPos, $1, $2, $i, $i2, $i3 Dim $StartPos[2^24] HotKeySet("{F1}", "RecordStart") HotKeySet("{F2}", "RecordStop") HotKeySet("{F3}", "Playback") While 1 WEnd Func _Exit() Exit EndFunc Func RecordStart() $i = 1 While 1 $StartPos[$i] = MouseGetPos(0) $i = $i + 1 Sleep(10) WEnd EndFunc Func RecordStop() Global $StopPos = MouseGetPos(0) EndFunc Func Playback() If $StopPos > $StartPos[1] Then $2 = True ElseIf $StopPos < $StartPos[1] Then $2 = False EndIf If $2 = True Then $MousePos = MouseGetPos(0) $i2 = 1 Do If $i2 = $i Then Call("Stop") $1 = $StopPos - $StartPos[$i2] MouseMove($MousePos + $1, MouseGetPos(1), 10) $i2 = $i2 + 1 Until $i2 > $i Call("Stop") ElseIf $2 = False Then $MousePos = MouseGetPos(0) $i3 = 1 Do If $i3 = $i Then Call("Stop") $1 = $StartPos[$i3] - $StopPos MouseMove($MousePos - $1, MouseGetPos(1), 10) $i3 = $i3 + 1 Until $i3 > $i Call("Stop") EndIf EndFunc Func Stop() Sleep(100) EndFunc the script works, but my problem is that it works twice. after i tell it to Playback it not only repeats the original left/right mouse movement by the exact pixels at the speed of 10, but once its done it'll move at speed 100 to the starting position and repeat again to the desired position at speed 100.... wtf? side notes: i've tried using "While $i2 < $i" loop, but it doesnt change anything. Edited April 13, 2010 by demandnothing Link to comment Share on other sites More sharing options...
BrettF Posted April 13, 2010 Share Posted April 13, 2010 Hi DemandNothing. Couple of things I've noticed with your script. With RecordStart, how do you expect it to behave when it reaches the end? A better way would be to define it like you have and check if the $i is greater than 2^24. Then use ReDim to make it larger again. Otherwise you will eventually run into an error. Ubound is a more failsafe method of seeing how large an array is. Also, Call is not necessary. Just use the function name just like you use a normal AutoIt function. Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
demandnothing Posted April 13, 2010 Author Share Posted April 13, 2010 (edited) Hi BrettF, The reason i used 2^24 as the array limit is because reading the documents on variables, thats the maximum it can go. If you could show me what you're talking about i would greatly appreciate it. However the problem i have as of now is that the MouseMove is only supposed to have the mouse move left/right, not left, right, then left again. Using the script as is, it'll move from wherever you have the mouse, to the left/right however far thats been recorded, then move right/left to where the mouse was before the script took action, and repeat back to the left/right however far is recorded. i need it to stop once its completed the action going left/right and not force the mouse to go back to the starting position and repeat itself like it does. That's why i added the Call() statements inside and outside the loop... thats why i even have Stop() as a function.. but its of no use. TBH: im not familiar with UBound LOL Edited April 13, 2010 by demandnothing Link to comment Share on other sites More sharing options...
BrettF Posted April 13, 2010 Share Posted April 13, 2010 Works fine: expandcollapse popup#include <Misc.au3> #include <Array.au3> $dll = DllOpen("user32.dll") $inc = 256 Dim $StartPos[$inc][2];x,y coords HotKeySet("{F1}", "RecordStart") HotKeySet("{F3}", "Playback") While 1 Sleep (10) WEnd Func _Exit() Exit EndFunc Func RecordStart() $i = 0 $size = UBound ($StartPos) While 1 If _IsPressed ("71", $dll) Then ExitLoop If $i >= $size Then $timer = TimerInit () ReDim $StartPos[$i + $inc][2] $size = UBound ($StartPos) EndIf $aPos = MouseGetPos () $StartPos[$i][0] = $aPos[0] $StartPos[$i][1] = $aPos[1] $i += 1 Sleep (50) WEnd _ArrayDisplay ($StartPos) ReDim $StartPos[$i][2] EndFunc Func Playback() _ArrayDisplay ($StartPos) For $i = 0 to UBound ($StartPos) - 1 If _IsPressed ("71", $dll) Then ExitLoop MouseMove ($StartPos[$i][0], $StartPos[$i][1]) Next EndFunc Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
demandnothing Posted April 13, 2010 Author Share Posted April 13, 2010 (edited) i appreciate you taking such time to show me that. Really helpful in learning how to use UBound, and helped to prevent future problems i was most likely going to have. However i still have my problem. i made cliff notes, and if you could copy this script to see what im talking about i would appreciate it. expandcollapse popup$inc = 256 Global $StopPos, $1, $2, $i, $i2, $i3, $MousePos Dim $StartPos[$inc] ;I only need the X coords HotKeySet("{F1}", "RecordStart") HotKeySet("{F2}", "RecordStop") HotKeySet("{F3}", "Playback") While 1 WEnd Func _Exit() Exit EndFunc Func RecordStart() $i = 0 $size = UBound ($StartPos) While 1 If $i >= $size Then $timer = TimerInit () ReDim $StartPos[$i + $inc] $size = UBound ($StartPos) EndIf $aPos = MouseGetPos (0) $StartPos[$i] = $aPos $i += 1 Sleep (10) WEnd ReDim $StartPos[$i] EndFunc ; This is only to record the left/right direction that the mouse moves, i dont need the Y coords.. THANK YOU for this. Func RecordStop() Global $StopPos = MouseGetPos(0) ; I need to record the StopPos so that i can tell if the mouse is moved left/right EndFunc Func Playback() If $StopPos > $StartPos[1] Then ; If the mouse is moved to the right $2 = True ElseIf $StopPos < $StartPos[1] Then ; If the mouse is moved to the left $2 = False EndIf If $2 = True Then ; If the mouse moves Right Then $MousePos = MouseGetPos(0) ; Find current MousePos X coord. $i2 = 0 Do If $i2 = $i - 1 Then Call("Stop") $1 = $StopPos - $StartPos[$i2] ; Do math to find how far to the right it was moved MouseMove($MousePos + $1, MouseGetPos(1), 10) ; Move the mouse from its current Pos however many pixels to the right $i2 = $i2 + 1 Until $i2 > $i Call("Stop") ElseIf $2 = False Then $MousePos = MouseGetPos(0) $i3 = 0 Do If $i3 = $i - 1 Then Call("Stop") $1 = $StartPos[$i3] - $StopPos MouseMove($MousePos - $1, MouseGetPos(1), 10) $i3 = $i3 + 1 Until $i3 > $i Call("Stop") EndIf EndFunc Func Stop() Sleep(100) EndFunc i want it to move however far was recorded to the left/right from its current position... not the starting position that was recorded. I apologize if my wording is confusing. But basically, i think, my problem is that i cant get the loop to stop once it reaches the desired stopping point. instead of the loop stopping the mouse movement after it goes however many pixels to the left/right it returns to the mouse position before Playback is called, and repeats itself. im confusing myself here... If i record the mouse moving 200 pixels left of X coord 700, and i have the mouse at X coord 800 when i call Playback, i want it to stop at X coord 600. but my problem is that it'll move to x coord 600, return to x coord 800, and back to 600 again... is that any easier to understand? instead of simply moving 200 pixels to the left, it'll return to where it started and repeat itself. Edited April 13, 2010 by demandnothing Link to comment Share on other sites More sharing options...
BrettF Posted April 14, 2010 Share Posted April 14, 2010 You want to play it in reverse? Or you want to move from the starting point to the end point? :S Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
demandnothing Posted April 14, 2010 Author Share Posted April 14, 2010 starting point to end point. only i want the starting point to be wherever they activated Playback from. Link to comment Share on other sites More sharing options...
demandnothing Posted April 15, 2010 Author Share Posted April 15, 2010 24 hour bump... MouseMove is such an easy thing i cant even believe its giving me problems like this.. but nobody has any idea what im doing wrong? Visually it doesn't appear there is anything wrong with the script.. i guess i just cant figure out how to get it to exit the loop once it reaches the desired position. 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