立即中止Lua脚本Logitech GHUB“在释放按钮”

嘿,各位,最近我开始尝试编写一些适用于Logitech GHUB的简单Lua脚本。 最终,我让它们按照我喜欢的方式工作,但我在这一个方面遇到了麻烦。 它不会在我释放Mouse5时立即停止,而是会继续执行脚本直到结束。 但是,我希望如果我释放Mouse 5,它能够立即停止。 我应该怎么做?

function OnEvent(event, arg)
  if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
    repeat
      Sleep(40)
      PressMouseButton(1)
      Sleep(1150)
      ReleaseMouseButton(1)
    until not IsMouseButtonPressed(5)
  end
end

感谢您的帮助 :-)

点赞
用户1847592
用户1847592
## 鼠标连点脚本

当鼠标第五个按钮被按下时,脚本开始连点操作。

每次点击鼠标左键后,会等待40毫秒。然后判断鼠标第五个按钮是否已被松开,如果被松开或者超过了1150毫秒,就停止连点。

```lua
function OnEvent(event, arg)
  if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
    -- 鼠标第五个按钮被按下
    repeat
      Sleep(40) -- 等待40毫秒
      PressMouseButton(1) -- 点击鼠标左键
      local tm = GetRunningTime()
      local exiting
      repeat
        Sleep(50) -- 等待50毫秒
        exiting = not IsMouseButtonPressed(5) -- 判断鼠标第五个按钮是否已被松开
      until exiting or GetRunningTime() - tm > 1150 -- 如果超过了1150毫秒就停止连点
      ReleaseMouseButton(1) -- 松开鼠标左键
    until exiting -- 如果鼠标第五个按钮被松开就停止连点
  end
end
2019-11-16 09:16:01