首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Logitech G Hub API Lua脚本

Logitech G Hub API Lua脚本
EN

Stack Overflow用户
提问于 2021-05-25 02:00:45
回答 1查看 1.5K关注 0票数 0

我编写了一个简单的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)

我的代码:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2021-08-29 08:15:41

请注意,您的事件处理程序函数在其自身的第4行中第二次被声明。

此外,EnablePrimaryMouseButtonEvents()不必多次调用或每次输入事件都调用-它可以放在函数外部,只运行一次。像第一行或最后一行这样的东西可能是个好主意。

最后,我认为自上而下的条件更加清晰。所以,给自己一点时间松开按钮,如果你这样做了,执行一次while循环,怎么样?如果您在重新检查按钮状态时按住按钮,则会停止循环:

代码语言:javascript
复制
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
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67676810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档