0

我试图在使用 Lua 的 Logitech GHUB 中制作一个自动点击器脚本。我尝试了很多变体,但我总是遇到语法错误。我以前没有编码经验。

代码的要点是,当我按住 P 时,鼠标反复单击并等待这些单击之间的随机间隔。还计划在新闻和发布之间进行间隔。

EnablePrimaryMouseEvents(true)

function OnEvent(event, arg)
    --OutputLogMessage("Event: "..event.." Arg: "..arg.."\n")

if IsKeyPressed("P") then 
    repeat 
        PressMouseButton(1)
        ReleaseMouseButton(1)
        Sleep(math.random(29, 36)) 
        PressMouseButton(1)
        ReleaseMouseButton(1) ---- Syntax Error(Show up almost everywhere when I change the code) 
    until not IsKeyPressed("P") then 
end
4

1 回答 1

0

你想要的是不可能的。
G-Hub 无法确定P按键是按下还是释放。
仅监视鼠标按钮(使用IsMouseButtonPressed)。
并且Shift/Alt/Ctrl密钥也被监控(使用IsModifierPressed)。
常用键(字母、数字)不受监控。

G-Hub 有一个错误:在编译时错误消息中,行号移动了一位。
因此,语法错误实际上指向了until not IsKeyPressed("P")因为关键字的行then。而且,顺便说一句, G-Hub
中没有定义函数。 您可以在菜单中阅读所有 G-Hub 功能的列表IsKeyPressed()
Help -> Scripting API

以下代码是由 Mouse Button #4 ("back") 而不是 key 控制的自动点击器示例P

EnablePrimaryMouseButtonEvents(true)

function OnEvent(event, arg)
   --OutputLogMessage("Event: "..event.." Arg: "..arg.."\n")
   if event == "MOUSE_BUTTON_PRESSED" and arg == 4 then 
      repeat 
         PressAndReleaseMouseButton(1)
         Sleep(math.random(30, 60)) 
      until not IsMouseButtonPressed(4)
   end
end
于 2020-12-18T13:29:25.987 回答