Sign in to follow this  
Followers 0
upnorth

MouseMove is so slow

4 posts in this topic

;~ #include<user32.au3>

Opt("MouseClickDelay", 0)    ;10 milliseconds
Opt("MouseClickDownDelay", 0) ;10 milliseconds
Opt("MouseClickDragDelay", 0);250 milliseconds
;~ I dont think these affect mousemove but just incase :)

$left = (@DesktopWidth - 1)
$bottom = (@DesktopHeight - 1)
$mm = 250
$scp = 5000

Dim $timer[3], $dll = DllOpen( "user32.dll")

#region - tests
beep( 2500, 100)

$timer[1] = TimerInit()
For $i = 1 To $mm
    MouseMove( Random( 0, $left, 1), Random( 0, $bottom, 1), 0)
Next
$timer[1] = TimerDiff($timer[1])

beep( 2500, 100)

$timer[2] = TimerInit()
For $i = 1 To $scp
    _SetCursorPos( Random( 0, $left, 1), Random( 0, $bottom, 1), $dll)
Next
$timer[2] = TimerDiff($timer[2])

beep( 2500, 100)
#endregion
DllClose( $dll)
MsgBox( 0, "Test complete.", "MouseMove( random, random, 0) * " & $mm & ": " & $timer[1] & @LF _
& "_SetCursorPos( random, random) * " & $scp & ": " & $timer[2])

Func _SetCursorPos( $x, $y, $dll_h = "user32.dll")
;~  http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/resources/cursors/cursorreference/cursorfunctions/setcursorpos.asp
    Local $return = DllCall( $dll_h, "int", "SetCursorPos", "int", $x, "int", $y)
    Return $return[0]
EndFunc

Share this post


Link to post
Share on other sites



untested theory:

MouseMove will move the cursor smoothly from current position to destination, allowing it to trigger any mouse-over events along the way; SetCursorPos just forces the pointer to a new location.

Anyone want to check that?

Share this post


Link to post
Share on other sites

A speed of 0 will move the mouse instantly.

MouseMove(x ,y ,0) should be as fast as SetCursorPos but it looks like it is about 60 to 70 times slower useing thius test.

;~ #include<user32.au3>

Opt("MouseClickDelay", 0)    ;10 milliseconds
Opt("MouseClickDownDelay", 0) ;10 milliseconds
Opt("MouseClickDragDelay", 0);250 milliseconds
;~ I dont think these affect mousemove but just incase :)

$left = (@DesktopWidth - 1)
$bottom = (@DesktopHeight - 1)
$mm = 20
$scp = 20
$tests = 25
$beep_delay = 1
$c = 0

Dim $timer[3], $timera[3], $dll = DllOpen( "user32.dll")


#region - tests
$timer[0] = TimerInit()
For $it = 1 to $tests

beep( 2500, $beep_delay)

$timer[1] = TimerInit()
For $i = 1 To $mm
    MouseMove( Random( 0, $left, 1), Random( 0, $bottom, 1), 0)
Next
$timer[1] = TimerDiff($timer[1])

beep( 2500, $beep_delay)

$timer[2] = TimerInit()
For $i = 1 To $scp
    _SetCursorPos( Random( 0, $left, 1), Random( 0, $bottom, 1), $dll)
Next
$timer[2] = TimerDiff($timer[2])

beep( 2500, $beep_delay)


$c += 1
$timera[1] += $timer[1]
$timera[2] += $timer[2]
Next
#endregion


$timera[0] = "ms=" & Int(TimerDiff($timer[0]))
$timera[1] = "ms=" & Int($timera[1] / $tests)
$timera[2] = "ms=" & Int($timera[2] / $tests)

DllClose( $dll)
MsgBox( 0, "Average out of " & $c & " tests:", "MouseMove( random, random, 0) * " & $mm & ": " & $timera[1] & @LF _
& "_SetCursorPos( random, random) * " & $scp & ": " & $timera[2] & @LF & "Total test time: " & $timera[0])

Func _SetCursorPos( $x, $y, $dll_h = "user32.dll")
;~  http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/resources/cursors/cursorreference/cursorfunctions/setcursorpos.asp
    Local $return = DllCall( $dll_h, "int", "SetCursorPos", "int", $x, "int", $y)
    Return $return[0]
EndFunc

Results...
---------------------------
Average out of 25 tests:
---------------------------

MouseMove( random, random, 0) * 20: ms=312
_SetCursorPos( random, random) * 20: ms=4
Total test time: ms=9002
...
MouseMove( random, random, 0) * 20: ms=313
_SetCursorPos( random, random) * 20: ms=4
Total test time: ms=9017
...
MouseMove( random, random, 0) * 20: ms=313
_SetCursorPos( random, random) * 20: ms=5
Total test time: ms=9010

Share this post


Link to post
Share on other sites

For now I tend to agree. I conducted my own test similar to UP NORTH's and SetCursorPos was indeed faster then MouseMove(), although the results were not quite 60-70x but more like 10x from what I can remember.


[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

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