Having problems with Sleep() func on MouseMoveRelative on LUA

主宰稳场 提交于 2021-01-29 07:13:04

问题


got a new drive and installed a fresh windows.

Before on old OS, i could use "Sleep" to make "MoveMouseRelative" work like it was natural movement.

i have created a function were i can move the mouse calling it with how many times i want it to "move"

and with the milliseconds between each "move" Example:(works well)

function _move(x, range, time, range2)
    for i = 1, x do
    MoveMouseRelative(range,range2)
    Sleep(time)
    end
end 

n

If i set "Sleep(1)" beteween each "MoveMouseRelative" it moves like it has like "Sleep(50)", i couldnt figure why.

if i call it with 50 Moves of 1ms it takes 2,5 seconds to finish instead of 50ms

on my old drive with the old OS install(same PC), i can use it normally takes 50ms

Its like the software wont let me use small ms such as 1 ms.

Tried

LGHUB Reinstall

deactivating AV

disabling things on windows,

copying the LGHUB folder from the OS that is working well

copying the LGHUB folder with the configs(LocalAppdata)

My Mouse is the G502 SE

Help?


回答1:


TL;DR:
Sleep(1) behavior is unstable and should not be used.
Sleep() has a much worse precision than you think it has.


Long answer:

Sleep() in LGHUB script internally invokes WinAPI function Sleep.

An excerpt from the documentations:

After the sleep interval has passed, the thread is ready to run. Note that a ready thread is not guaranteed to run immediately. Consequently, the thread may not run until some time after the sleep interval elapses.

The system clock "ticks" at a constant rate. If dwMilliseconds is less than the resolution of the system clock, the thread may sleep for less than the specified length of time. If dwMilliseconds is greater than one tick but less than two, the wait can be anywhere between one and two ticks, and so on.

The "tick" here is the "time slice" length which is 15ms on my Windows (but it could be 10ms on another Windows versions).

As you see from the documentation above, the Sleep() function has precision of one "tick", so behavior of Sleep(1) is unstable by design.



来源:https://stackoverflow.com/questions/64564344/having-problems-with-sleep-func-on-mousemoverelative-on-lua

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