LUA的MouseMoveRelative上的Sleep()函数有问题 [英] Having problems with Sleep() func on MouseMoveRelative on LUA

查看:166
本文介绍了LUA的MouseMoveRelative上的Sleep()函数有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获得了一个新的驱动器并安装了一个新的Windows.

在使用旧版OS之前,我可以使用睡眠"制作"MoveMouseRelative"像自然运动一样工作.

我已经创建了一个函数,可以移动鼠标调用它一次,让它移动"

以及每次移动"之间的毫秒数.例子:(效果很好)

 函数_move(x,range,time,range2)对于我= 1,x做MoveMouseRelative(range,range2)睡觉时间)结尾结尾 

n

如果我将"Sleep(1)"设置为在每个"MoveMouseRelative"之间.它像"Sleep(50)"一样移动,我无法弄清楚为什么.

如果我以1ms的50次移动来调用它,则完成需要2.5秒,而不是50ms

在装有旧操作系统安装(同一台PC)的旧驱动器上,我通常需要50毫秒才能使用

就像软件不会让我使用1毫秒这样的小毫秒.

尝试过

LGHUB重新安装

停用AV

禁用Windows上的功能

从运行良好的操作系统中复制LGHUB文件夹

使用configs(LocalAppdata)复制LGHUB文件夹

我的鼠标是G502 SE

帮助?

解决方案

TL; DR:
Sleep(1)行为不稳定,不应使用.
Sleep()的精度比您想象的要差得多.


长答案:

LGHUB脚本中的

Sleep()在内部调用WinAPI函数

勾号"这是时间片"长度在我的Windows上是15毫秒(但在其他Windows版本上可能是10毫秒).

从上面的文档中可以看到, Sleep()函数的精度为一个"tick",因此 Sleep(1)的行为在设计上是不稳定的

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?

解决方案

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.

这篇关于LUA的MouseMoveRelative上的Sleep()函数有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆