Logitech Lua Sleep Behavior

▼魔方 西西 提交于 2021-01-29 17:14:39

问题


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:


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.



来源:https://stackoverflow.com/questions/65356366/logitech-lua-sleep-behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!