larcerkev Posted August 2, 2011 Share Posted August 2, 2011 I was wondering if there would be a way to get the mouse to move not at a percent, but over a certain time period. Has anyone written a function for something like this before? Link to comment Share on other sites More sharing options...
monoscout999 Posted August 2, 2011 Share Posted August 2, 2011 i don`t get it. What percent? MouseMove uses Coordenates. Link to comment Share on other sites More sharing options...
larcerkev Posted August 2, 2011 Author Share Posted August 2, 2011 It uses x,y,percent speed. I want something that will do x,y,ms ms being milliseconds to execute the whole movement Link to comment Share on other sites More sharing options...
monoscout999 Posted August 2, 2011 Share Posted August 2, 2011 it is a little buggy for me but if you use maths you can create a function to do that. Link to comment Share on other sites More sharing options...
larcerkev Posted August 3, 2011 Author Share Posted August 3, 2011 it is a little buggy for me but if you use maths you can create a function to do that.I was thinking about doing that, but I'm not sure how I would approach it in the best manner. Link to comment Share on other sites More sharing options...
smartee Posted August 3, 2011 Share Posted August 3, 2011 Well take a shot at it, post your code, and we will guide you accordingly Link to comment Share on other sites More sharing options...
larcerkev Posted August 3, 2011 Author Share Posted August 3, 2011 (edited) MoveMouse(500,500,1000) Func MoveMouse($X,$Y,$MS) $TotalMoves=$MS/10 $MousePos=MouseGetPos() $xMS=($x-$MousePos[0])/($MS/10) $yMS=($y-$MousePos[1])/($MS/10) $Movement=1 While $Movement<$TotalMoves MouseMove($MousePos[0]+$XMS,$MousePos[1]+$yMS,0) $Movement+=1 $MousePos=MouseGetPos() Sleep(10) WEnd EndFunc Edited August 3, 2011 by larcerkev Link to comment Share on other sites More sharing options...
MvGulik Posted August 3, 2011 Share Posted August 3, 2011 With Sleep(10) you make 100 adjustments per second. That's kinda high(overkill) for something like this. Suggest you try sleep(100) (10 moves per second) of sleep(50) (20 moves per second) "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
monoscout999 Posted August 3, 2011 Share Posted August 3, 2011 MoveMouse(500,500,1000) Func MoveMouse($X,$Y,$MS) $TotalMoves=$MS/10 $MousePos=MouseGetPos() $xMS=($x-$MousePos[0])/($MS/10) $yMS=($y-$MousePos[1])/($MS/10) $Movement=1 While $Movement<$TotalMoves MouseMove($MousePos[0]+$XMS,$MousePos[1]+$yMS,0) $Movement+=1 $MousePos=MouseGetPos() Sleep(10) WEnd EndFunc Nice Done It works very well. Link to comment Share on other sites More sharing options...
jaberwacky Posted August 3, 2011 Share Posted August 3, 2011 Except when $totalmoves doesn't divide evenly. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
jaberwacky Posted August 3, 2011 Share Posted August 3, 2011 (edited) I'm thinking of this: 1) Find the length of time it takes to move the mouse one pixel on any given machine. 2) Find out how many pixels you are away from your destination. 3) Divide $MS by the value obtained in step one. 4) that is how many steps should taken to move the mouse from home to destination. To figure out the exact pixels you should use should be a graph. Figure out how many pixels to step up by and to step over by. ___| | ___| | | No, scratch that, it's stupid. Edited August 3, 2011 by LaCastiglione Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
MvGulik Posted August 3, 2011 Share Posted August 3, 2011 (edited) No, scratch that, it's stupid.Why? The one pixel perhaps. But that could be 'small integer jump value'generalRemember that MouseMove() acts like MouseMove(floor($float), floor($float)) -> rounding error when using floats.+(or (probably) int() instead of floor() of course.) nope, its floored. Edited August 3, 2011 by iEvKI3gv9Wrkd41u "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
larcerkev Posted August 3, 2011 Author Share Posted August 3, 2011 I did realize taking it in 10 MS intervals was a mistake when I put it to use because it happened to be over shooting places, and causing some really weird activities. But the main objective is to make it look like a normal mouse but also move perfectly to the point no matter what $MS equals. I guess really the only way would be to use something like 1 ms per interval. But that would be over kill. Link to comment Share on other sites More sharing options...
GEOSoft Posted August 3, 2011 Share Posted August 3, 2011 Be careful how you word your posts."happened to be over shooting places" caught my attention immediately George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
MvGulik Posted August 3, 2011 Share Posted August 3, 2011 I did realize taking it in 10 MS intervals was a mistake when I put it to use because it happened to be over shooting places, and causing some really weird activities. But the main objective is to make it look like a normal mouse but also move perfectly to the point no matter what $MS equals. I guess really the only way would be to use something like 1 ms per interval. But that would be over kill.Using 10 is not the problem. (and you can't set sleep() to use anything lower. (except sleep(0), which is of no use here)(And sleep(100) looks like crap.)The problem in your code is that you assume the float value to remain a float, but by using MouseMove()+MouseGetPos() your flooring it at every jump. Ergo the under- or over-shooting of the moved-cursor compared to the set target position. "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
MvGulik Posted August 3, 2011 Share Posted August 3, 2011 One way ...expandcollapse popup_MoveMouse(500, 500, 500, 2) Func _MoveMouse($ixTarget, $iyTarget, $iMoveTime, $iTimestep = 1) $iTimestep *= 10 ;; or 11 if I recall corectly. ;~ Local $iMouseCoordMode_old = Opt('MouseCoordMode',1) ;~ If Not BlockInput(1) Then DebugOut('BlockInput(1) failed, ignored.') ;### Debug DebugOut. Local $iMoves = Round($iMoveTime / $iTimestep) ;; just making it a int, no need for it to be a float. Local $aMousePos = MouseGetPos() ;; ditching array. (as where not going to use MouseGetPos() in the loop.) Local Enum $_x_, $_y_ Local $ixCurrent = $aMousePos[$_x_] Local $iyCurrent = $aMousePos[$_y_] $aMousePos = '' ;; not used anymore. Local $nxStep = ($ixTarget - $ixCurrent) / $iMoves Local $nyStep = ($iyTarget - $iyCurrent) / $iMoves Local $iMove = 1 ;; keep track of target location, including maintaining float value. Local $nxNew = $ixCurrent + $nxStep Local $nyNew = $iyCurrent + $nyStep $ixCurrent = '' ;; not used anymore. $iyCurrent = '' ;; not used anymore. While $iMove < $iMoves $nxNew += $nxStep $nyNew += $nyStep ;~ MouseMove($nxNew, $nyNew, 0) MouseMove(round($nxNew), round($nyNew), 0) ;~ ;; compare/debug ;~ DebugOut('MouseGetPos()', MouseGetPos()) ;### Debug DebugOut. Sleep($iTimestep) $iMove += 1 WEnd ;~ BlockInput(0) ;~ Opt('MouseCoordMode',$iMouseCoordMode_old) EndFunc "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
larcerkev Posted August 3, 2011 Author Share Posted August 3, 2011 One way ...expandcollapse popup_MoveMouse(500, 500, 500, 2) Func _MoveMouse($ixTarget, $iyTarget, $iMoveTime, $iTimestep = 1) $iTimestep *= 10 ;; or 11 if I recall corectly. ;~ Local $iMouseCoordMode_old = Opt('MouseCoordMode',1) ;~ If Not BlockInput(1) Then DebugOut('BlockInput(1) failed, ignored.') ;### Debug DebugOut. Local $iMoves = Round($iMoveTime / $iTimestep) ;; just making it a int, no need for it to be a float. Local $aMousePos = MouseGetPos() ;; ditching array. (as where not going to use MouseGetPos() in the loop.) Local Enum $_x_, $_y_ Local $ixCurrent = $aMousePos[$_x_] Local $iyCurrent = $aMousePos[$_y_] $aMousePos = '' ;; not used anymore. Local $nxStep = ($ixTarget - $ixCurrent) / $iMoves Local $nyStep = ($iyTarget - $iyCurrent) / $iMoves Local $iMove = 1 ;; keep track of target location, including maintaining float value. Local $nxNew = $ixCurrent + $nxStep Local $nyNew = $iyCurrent + $nyStep $ixCurrent = '' ;; not used anymore. $iyCurrent = '' ;; not used anymore. While $iMove < $iMoves $nxNew += $nxStep $nyNew += $nyStep ;~ MouseMove($nxNew, $nyNew, 0) MouseMove(round($nxNew), round($nyNew), 0) ;~ ;; compare/debug ;~ DebugOut('MouseGetPos()', MouseGetPos()) ;### Debug DebugOut. Sleep($iTimestep) $iMove += 1 WEnd ;~ BlockInput(0) ;~ Opt('MouseCoordMode',$iMouseCoordMode_old) EndFunc Yours seems to be able to take a large variation of inputs for the MS and work just fine. I'm going to take a bit and study this to understand it more. 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