2

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 :-)

Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
Peter Lustig
  • 21
  • 1
  • 2
  • 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 Nov 16 '19 at 00:21

1 Answers1

0
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
Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
  • That works like a charme! Thank you so much for helping me out with this one !!!! – Peter Lustig Nov 18 '19 at 16:44
  • Oh btw. Do you know by any chance how I could bin that to the Mouse 7 Button? Because it won't recognize "IsMouseButtonPressed (7) since only 1-5 work that way I think... – Peter Lustig Nov 18 '19 at 17:46
  • 1
    @PeterLustig - You can make a looped macro (for pressing and releasing LMB), run this macro on Button7 press and abort this macro on Button7 release. – Egor Skriptunoff Nov 18 '19 at 18:35
  • how do I make a macro that aborts on release though? – Peter Lustig Nov 18 '19 at 20:32
  • 1
    @PeterLustig - `if event == "MOUSE_BUTTON_PRESSED" and arg == 7 then PlayMacro("YourMacroName") end; if event == "MOUSE_BUTTON_RELEASED" and arg == 7 then AbortMacro(); ReleaseMouseButton(1) end` – Egor Skriptunoff Nov 18 '19 at 21:23