Sign in to follow this  
Followers 0
larcerkev

More Precise Mouse Movement?

17 posts in this topic

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?

Share this post


Link to post
Share on other sites



i don`t get it.

What percent? MouseMove uses Coordenates.

Share this post


Link to post
Share on other sites

It uses x,y,percent speed.

I want something that will do x,y,ms ms being milliseconds to execute the whole movement

Share this post


Link to post
Share on other sites

it is a little buggy for me but if you use maths you can create a function to do that.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Well take a shot at it, post your code, and we will guide you accordingly :mellow:

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by larcerkev

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by LaCastiglione

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

No, scratch that, it's stupid.

Why? The one pixel perhaps. But that could be 'small integer jump value'

general

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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!"

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

One way ...

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

Share this post


Link to post
Share on other sites

One way ...

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0