我编写了一个简单的Lua脚本,在单击mouse5后单击鼠标。问题是,在第12行,如果我包含'not‘,它只会重复一次,如果我删除它,它将永远重复。如果可能的话,我想用mouse5开始和结束脚本。我知道人们以前也遇到过与我类似的问题,但我无法找到解决方案。有什么想法吗?
我使用的是Logitech G Hub API:(https://douile.github.io/logitech-toggle-keys/APIDocs.pdf)
这是我的循环:(https://www.tutorialspoint.com/lua/lua_repeat_until_loop.htm)
我的代码:
function OnEvent(event, arg)
OutputLogMessage("Event: "..event.." Arg: "..arg.."\n")
EnablePrimaryMouseButtonEvents(true)
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
repeat
Sleep(math.random(1046, 1292))
PressMouseButton(1)
Sleep(math.random(27, 78))
ReleaseMouseButton(1)
Sleep(math.random(314, 664))
until not IsMouseButtonPressed(5)
end
end
end发布于 2021-08-29 08:15:41
请注意,您的事件处理程序函数在其自身的第4行中第二次被声明。
此外,EnablePrimaryMouseButtonEvents()不必多次调用或每次输入事件都调用-它可以放在函数外部,只运行一次。像第一行或最后一行这样的东西可能是个好主意。
最后,我认为自上而下的条件更加清晰。所以,给自己一点时间松开按钮,如果你这样做了,执行一次while循环,怎么样?如果您在重新检查按钮状态时按住按钮,则会停止循环:
EnablePrimaryMouseButtonEvents(true)
function OnEvent(e,a)
OutputLogMessage("Event: "..e.." Argument: "..a.."\n")
if e=="MOUSE_BUTTON_PRESSED" and a==5 then
Sleep(200)
while not IsMouseButtonPressed(5) do
Sleep(math.random(1046,1292))
-- maybe add another check here "if IMBP(5) then return end"
PressMouseButton(1)
Sleep(math.random(27,78))
ReleaseMouseButton(1)
Sleep(math.random(314,664))
end end
endhttps://stackoverflow.com/questions/67676810
复制相似问题