2
votes

Hey guys I recently started trying to write some simple Lua Scripts for Logitech GHUB. I finally got them working the way I like but I'm having troubles with this one. Instead of instantly stopping when I release Mouse5 it will continue to execute the script till the end. I want it however to immediately stop if I release Mouse 5. How do I do that?

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

Thanks for your help :-)

1
Hey it works fine but I want the script to immediately stop when i release the button. Now it will continue to execute till the end. For example if I release Button 5 it will keep shooting... - Peter Lustig

1 Answers

0
votes
function OnEvent(event, arg)
  if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
    repeat
      Sleep(40)
      PressMouseButton(1)
      local tm = GetRunningTime()
      local exiting
      repeat
        Sleep(50)
        exiting = not IsMouseButtonPressed(5)
      until exiting or GetRunningTime() - tm > 1150
      ReleaseMouseButton(1)
    until exiting
  end
end