I need to move mouse cursor from coordinates (800,300) to (100,600) with visible cursor movement. How can I do that? (I need to simulate motion only - I am getting mouse position with autopy module)
Asked
Active
Viewed 7,190 times
1 Answers
3
Directly from the docs:
import autopy
autopy.mouse.move(800, 300)
autopy.mouse.smooth_move(100, 600)
This first moves to the location and then linearly slides the mouse to the second location. With a combination of pauses, you can use autopy.mouse.move
to move as slow or as fast as you want.
Edit by request: To a finer control over the smooth_move
you can set the mouse position yourself. Here, I set the total_time to be 5.00
seconds, but you can change this to be as quick as you like.
from __future__ import division
import autopy
import time
x0, y0 = 800, 300
xf, yf = 100, 600
total_time = 5.00 # in seconds
draw_steps = 1000 # total times to update cursor
dx = (xf-x0)/draw_steps
dy = (yf-y0)/draw_steps
dt = total_time/draw_steps
for n in xrange(draw_steps):
x = int(x0+dx*n)
y = int(y0+dy*n)
autopy.mouse.move(x,y)
time.sleep(dt)

Hooked
- 84,485
- 43
- 192
- 261
-
Thanks, I know smooth move but it is too slow. Any other idea? – peter Jan 17 '15 at 23:53
-
@peter Sure, like I mentioned, use a loop that uses `os.sleep` and `autopy.mouse.move` that moves it small increments. If this doesn't make sense, let me know and I'll try to code up an example when I'm by a computer (not phone) again. – Hooked Jan 18 '15 at 02:27
-
Thanks @Hooked. I tried with sleep function but no luck. Could you please provide me with small example how to code it? Many thanks! – peter Jan 18 '15 at 08:46