【问题标题】:why am i getting a syntax error in my logitech g lua script?为什么我的 logitech g lua 脚本出现语法错误?
【发布时间】:2021-12-02 12:25:12
【问题描述】:

我一直在学习 lua 为我的 g903 编写一个自动点击器,当按住鼠标右键并且可以使用 capslock 键切换时,它可以工作。 任何帮助或见解将不胜感激

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event,arg)=true
    if IsKeyLockOn("capslock"=true then
        if IsMouseButtonPressed(3)=true then
            repeat
                if IsMouseButtonPressed(1)=true then
                    repeat
                        PressAndReleaseMouseButton(1)
                        Sleep(math.random(20,80))
                    until IsMouseButtonPressed(1)=false
                end
            until IsMouseButtonPressed(3)=false
        end
    end
end

【问题讨论】:

  • 能否请您也发布错误?
  • 你认为function OnEvent(event,arg)=true是什么意思?
  • 还有,你知道===的区别吗?
  • 不能同时模拟虚拟LMBPressAndReleaseMouseButton(1)和监控物理LMB状态IsMouseButtonPressed(1)

标签: lua logitech logitech-gaming-software


【解决方案1】:

function OnEvent(event,arg) 是函数定义的开始。您不能像在function OnEvent(event,arg)=true 中尝试的那样在此处设置为真。这将为“=”附近的意外符号提供错误。 Lua 无法理解这一点。

if IsKeyLockOn("capslock"=true then 中,您缺少一个括号。添加后,对于以下所有行,它仍然不正确:

if IsKeyLockOn("capslock")=true then
if IsMouseButtonPressed(3)=true then
if IsMouseButtonPressed(1)=true then

在“=”附近出现错误“then”

until IsMouseButtonPressed(1)=false
until IsMouseButtonPressed(3)=false

您会在“直到”附近收到错误“”

您将赋值运算符 = 与相等运算符 == 混淆了。

Relational OperatorsAssignment

附带说明,这些函数已经返回 true 或 false。

您不必明确检查返回值是否等于 true。只有两种可能的结果。 true == true -> truefalse == true -> false。所以可以直接使用返回值,直接写if IsMouseButtonPressed(1) then即可。

如果你想在false 的情况下做一些事情,通常的做法是简单地否定返回值。 not false -> true

在这种情况下,您只需写 if not if not IsMouseButtonPressed(1) then 而不是 if IsMouseButtonPressed(1) == false then

【讨论】:

  • 另外,IsMouseButtonPressed 等返回一个布尔值。将布尔值与true 进行比较实际上没有任何作用,因此您可以删除所有== true。与== false 类似,更常见的是使用not
  • 我按照您的建议修复了代码,现在它没有显示任何错误,并且根据 ghub 似乎“工作”,但脚本仍然没有注册点击。
  • 当前代码如下; EnablePrimaryMouseButtonEvents(true); function OnEvent(event,arg) if IsKeyLockOn("capslock") then if IsMouseButtonPressed(3) then repeat if IsMouseButtonPressed(1) then repeat PressAndReleaseMouseButton(1) Sleep(math.random(20,80)) until not IsMouseButtonPressed(1) end until not IsMouseButtonPressed(3) end end end
  • 请提出一个新问题
猜你喜欢
  • 2012-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多