'Logitech lua reliable Sleep
Introduction
I am writing a lua script for my logitech mouse. The logitech lua api has this documentation.
My script moves the mouse every x milliseconds to draw a pattern. My problem is that the Sleep(x) function of this lua api is very inaccurate. I have read that it takes time (couple milliseconds) for it to get a thread, so that time adds to the execution time for the code itself. However it makes it useless for measuring milliseconds.
Question
Do you know a workaround? Is there a more capable way for measuring milliseconds than the Sleep(x) function?
Also I wanted to note that in windows 10 version 1909 and bellow, it was much-much more accurate. They have messed something with it so it is inaccurate since windows 10 version 2004 (aruound august, last year). So I would need to find a workaround for this.
My Code
Here is a snippet from my code:
PressMouseButton(1)
--1
MoveMouseRelative(-26, 36)
Sleep(127)
--2
MoveMouseRelative(2, 36)
Sleep(127)
--3
MoveMouseRelative(-36, 32)
Sleep(127)
--4
MoveMouseRelative(-33, 30)
Sleep(127)
--5
MoveMouseRelative(-11, 38)
Sleep(127)
ReleaseMouseButton(1)
This does not work on its own, but you can see here how I want to use the function. Thank you for your help!
Solution 1:[1]
Sleep
is not for measuring milliseconds. It pauses your script for a certain amount of time.
From what I can see it is not possible to load any libraries from a Logitech script.
So you can only use Sleep
or run a loop to delay.
Solution 2:[2]
Send you a logitech high-precision delay, accurate to 1ms, why high precision, because win10 1909 after the system version, logitech script 1ms=15.6ms, so need
function Sleep3(time)
local a = GetRunningTime()
while GetRunningTime()-a < time do
end
end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Piglet |
Solution 2 | Andro |