GHUB Lua - Slow Mouse Movement Function

89 Views Asked by At

I am trying to create a local function in Lua (GHUB) to move the mouse to a specific coordiinates on the screen. However the pointer moves suddenly at the end of the function call ... and does not even go to the right position. Also .. is there anyway I can debug Lua ... in GHUB is practically impossible from what I see. Not even syntax errors.

Thank you!

local function MouseMoveToSlower(x, y, speed)
    current_x, current_y = GetMousePosition()
    distance = math.sqrt((x - current_x)^2 + (y - current_y)^2)
    steps = math.floor(distance / speed)

    for i = 1, steps do
        new_x = current_x + (x - current_x) * i / steps
        new_y = current_y + (y - current_y) * i / steps
        MoveMouseRelative(new_x - current_x, new_y - current_y)
        Sleep(math.random(102,125))
    end
end
1

There are 1 best solutions below

4
On

MoveMouseRelative expects distance in 1 pixel units (screen width = 1920 units)
GetMousePosition returns distance in (screen_size)/64K units (screen width = 65536 units)
You should convert values correctly.