0

I am trying to create a script in .lua on GHub for my mouse. I have to make a lot of movements really quickly, inputting 10 MoveMouseRelative every second and a half. But I have found that the positions change a lot where they shouldn't. During my tests I discovered that the script is executed in different timespans, like, a certain line should be run at second 2, and sometimes it's executed on second 2.1 or 1.9. I think it's because of the available processing power in my computer, but I don't know for sure. What can I do to fix that and have sure that the script is executed always on the same timespan and that the positions are always the same?

I made some tests and the scrip always executes in a different way every time I test it I want it to be able to execute the same way every time

    function OnEvent(event, arg)
    OutputLogMessage("Event: "..event.." Arg: "..arg.."\n")
    if IsMouseButtonPressed(3) then
      repeat
      if IsMouseButtonPressed(1) then  Sleep(11)
      repeat
--2
Sleep(11)
MoveMouseRelative(-1, 8)
Sleep(11)
MoveMouseRelative(-1, 7)
Sleep(11)
MoveMouseRelative(0, 6)
Sleep(11)
MoveMouseRelative(0, 6)
Sleep(11)
MoveMouseRelative(0, 6)
Sleep(11)
MoveMouseRelative(0, 5)
Sleep(11)
MoveMouseRelative(0, 5)
Sleep(11)
MoveMouseRelative(0, 2)
Sleep(11)
MoveMouseRelative(0, 2)
Sleep(11)
MoveMouseRelative(0, 2)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--3
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--4
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12) 
--5
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--6
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--7
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--8
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--9
Sleep(11)
MoveMouseRelative(-3, 4)
Sleep(11)
MoveMouseRelative(-3, 4)
Sleep(11)
MoveMouseRelative(-3, 4)
Sleep(11)
MoveMouseRelative(-3, 4)
Sleep(11)
MoveMouseRelative(-3, 4)
Sleep(11)
MoveMouseRelative(-3, 4)
Sleep(11)
MoveMouseRelative(-3, 4)
Sleep(11)
MoveMouseRelative(-3, 4)
Sleep(11)
MoveMouseRelative(-3, 4)
Sleep(11)
MoveMouseRelative(-3, 4)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--10
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--11
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-200, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--12
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--13
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--14
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--15
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--16
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--17
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--18
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--19
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--20
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--21
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--22
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--23
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--24
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--25
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--26
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--27
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--28
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--29
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
--30
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
Sleep(11)
MoveMouseRelative(-2, 3)
if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then break end
Sleep(12)
until not IsMouseButtonPressed(1)
 end
      until not IsMouseButtonPressed(3)
    end
end

1 Answer 1

0

During my tests I discovered that the script is executed in different timespans, like, a certain line should be run at second 2, and sometimes it's executed on second 2.1 or 1.9.

This is because of Sleep() is very inexact, its precision is 15 ms.
Anyway, you can guarantee the interval 1.985-2.015 seconds (it is better than 1.9-2.1)

You should prepare all the trajectory as sequence of (dx, dy, ms) triples: x-move in pixels, y-move in pixels, time in milliseconds.

For example, the following block of code

    Sleep(11)
    MoveMouseRelative(0, 6)
    Sleep(11)
    MoveMouseRelative(0, 6)
    Sleep(11)
    MoveMouseRelative(0, 6)

corresponds to moving at constant direction with constant speed, such a move can be described as a line segment of the trajectory:

   {dx = 0, dy = 18, ms = 33}

The full script:

local trajectory = {
   -- Sleep(11)
   -- MoveMouseRelative(-1, 8)
   -- Sleep(11)
   -- MoveMouseRelative(-1, 7)
   {dx = -2, dy = 15, ms = 22},

   -- Sleep(11)
   -- MoveMouseRelative(0, 6)
   -- repeated 3 times
   {dx = 0, dy = 18, ms = 33},

   -- Sleep(11)
   -- MoveMouseRelative(0, 5)
   -- repeated 2 times
   {dx = 0, dy = 10, ms = 22},

   -- Sleep(11)
   -- MoveMouseRelative(0, 2)
   -- repeated 3 times
   {dx = 0, dy = 6, ms = 33},

   --3..8
   -- Sleep(11)
   -- MoveMouseRelative(-2, 3)
   -- repeated 60 times
   {dx = -120, dy = 180, ms = 660},

   --9
   -- Sleep(11)
   -- MoveMouseRelative(-3, 4)
   -- repeated 10 times
   {dx = -30, dy = 40, ms = 110},

   --10..11
   -- Sleep(11)
   -- MoveMouseRelative(-2, 3)
   -- repeated 12 times
   {dx = -36, dy = 48, ms = 132},

   -- Sleep(11)
   -- MoveMouseRelative(-200, 3)
   {dx = -200, dy = 3, ms = 11},

   --11..30
   -- Sleep(11)
   -- MoveMouseRelative(-2, 3)
   -- repeated 197 times
   {dx = -394, dy = 591, ms = 2167},
}

EnablePrimaryMouseButtonEvents(true)

function OnEvent(event, arg)
   OutputLogMessage("Event: "..event.." Arg: "..arg.."\n")
   local line_end_time = GetRunningTime()
   local x, y = 0, 0
   for _, line in ipairs(trajectory) do
      local speed_x, speed_y = line.dx / line.ms, line.dy / line.ms
      local prev_time = line_end_time
      line_end_time = line_end_time + line.ms
      repeat
         Sleep(10)
         if not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3)) then return end
         local tm = math.min(GetRunningTime(), line_end_time)
         tm, prev_time = tm - prev_time, tm
         x, y = x + speed_x * tm, y + speed_y * tm
         local dx, dy = math.floor(x + 0.5), math.floor(y + 0.5)
         x, y = x - dx, y - dy
         while dx ~= 0 or dy ~= 0 do
            local mx = math.abs(dx) <= 127 and dx or math.abs(dx)/dx * 127
            local my = math.abs(dy) <= 127 and dy or math.abs(dy)/dy * 127
            dx, dy = dx - mx, dy - my
            MoveMouseRelative(mx, my)
         end
      until prev_time == line_end_time
   end
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.