0
votes

Since Egor always help, this is intended to show him the problem, but if you know how to solve, please help too!

https://youtu.be/J2vRfnUplio <<< this is how the script should work. (look at the descripition for more info)

https://youtu.be/HH_MmfXUdl8 <<< This is how it doing now, at windows newer versions.

Having problems with Sleep() func on MouseMoveRelative on LUA

^^ This is the last question that shows the problem and you helped me there

GHUB has the same version on both, so isnt GHUB the problem.

Sleep(1) wont behave like it should, my best guess is that windows changed something but WHAT is the question.

Someone help?

1
You should avoid using Sleep(1). Its behavior depends on Windows version, number of CPU cores and total CPU load. Sleep has 15 ms precision. And you never really need 1 ms precision when simulating mouse movement. The solution to your problem is to recalculate the mouse trajectory using 30 ms time intervals and use Sleep(30) in your code. To make mouse move faster increase dx and dy instead of decreasing delay.Egor Skriptunoff
You was just lucky enough with Sleep(1) in the previous Windows versions. Do not rely on luck. Write robust and stable code.Egor Skriptunoff
But i need the code to be that way, Else it would be too slow, or without the sleep("sleep(0)") it gets really snappy if i could i would use it with higher sleep() ms. its a windows setting that changed i just have to figure it out. i have reached Logitech devs but they are taking too long to answer, and last time they just sent me an auto msg with some generic actions, like they hadnt read what i sent them.Salles
Please post your program which really needs 1 ms delay. I'll help you to modify it to 30 ms intervals without losing visual quality. Your monitor displays new frame every 16 ms (in 60 FPS game). You don't need to refresh mouse cursor more frequently than once per 16 ms.Egor Skriptunoff
Sleep(1) actually means "wait from 0 to 15 ms, IDK how long exactly". It is not suitable for simulating mouse movement.Egor Skriptunoff

1 Answers

1
votes

Insert the following block of code at the beginning of your script

do
   local function busyloop(final_ctr)
      final_ctr = final_ctr - final_ctr%1
      local ctr, prev_ms, ms0, ctr0 = 0
      while ctr ~= final_ctr do
         local ms = GetRunningTime()
         if prev_ms and ms ~= prev_ms then
            if not ms0 then
               ms0, ctr0 = ms, ctr
            elseif final_ctr < 0 and ms - ms0 > 500 then
               return (ctr - ctr0) / (ms - ms0)
            end
         end
         prev_ms = ms
         ctr = ctr + 1
      end
   end
   local coefficient = busyloop(-1)
   function FastSleep(ms)
      return busyloop(ms * coefficient)
   end
end

After that you can use function FastSleep(delay) in your script for small time intervals.

Example:

FastSleep(0.5)  -- wait for 0.5 ms

For big time intervals (for example, 30 ms or more) standard Sleep() is preferred.