0

I want to move the cursor position from current position to given (X,Y), in a given time. I tried this way-

import win32api as api
import win32gui as gui
import time
import math
def moveMouse(x,y):
    api.SetCursorPos((x,y))

def move_slowly(x2,y2,total_time):
    x0, y0 = api.GetCursorPos()

    draw_steps = int(math.sqrt(math.pow(x0-x2,2) + math.pow(y0-y2,2)))

    dx = (x2-x0)/draw_steps #how much x to move each step
    dy = (y2-y0)/draw_steps #how much y to move each step
    dt = total_time/draw_steps #time between each step

    for n in range(draw_steps):
        x = int(x0+dx*n)
        y = int(y0+dy*n)
        moveMouse(x,y)
        time.sleep(dt)

But the time is always a bit off. I heard that it could be done using autopy, but no matter how i try- i couldn't download that library. any help?

Dolev Goaz
  • 41
  • 5

0 Answers0