luamouselogitechlogitech-gaming-software

Logitech Lua Sleep Behavior


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?


Solution

  • Insert the following block of code at the beginning of your script, before OnEvent() function

    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.