Reputation: 1
This is my attempt to make a Logitech high-precision delay, accurate to 1ms.
Why do you need high precision delay? Because starting with Win10 release 2004, Logitech Sleep(1)
is actually sleeps for 15.6ms, so you might need a more precise Sleep()
to preserve the original (Win10 1909) behavior of your old scripts.
function Sleep3(time)
local a = GetRunningTime()
while GetRunningTime()-a < time do
end
end
Is Sleep3()
accuracy really equals to 1ms?
Upvotes: 0
Views: 962
Reputation: 1
function OnEvent(event,arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 4 then
a = GetRunningTime()
for i = 1,1000,1 do
Sleep(1)
end
OutputLogMessage((GetRunningTime() - a) / 1000)
end
end
Upvotes: -1
Reputation: 23767
Logitech GetRunningTime()
just invokes WinAPI function GetTickCount
As you can see from the doc,
The resolution of the GetTickCount function is limited to the resolution of the system timer, which is typically in the range of 10 milliseconds to 16 milliseconds
In other words, the values returned by GetRunningTime()
are not sequential integers.
When you call GetRunningTime()
in a loop, you will receive something like the following:
0,0,0,...,0,15,15,15,...,15,31,31,..,31,46,46,...
This means it is unable to make 1ms-precision delay by using GetRunningTime()
.
The actual precision of Sleep3()
is 15ms, as usual Sleep()
has.
Upvotes: 2