Lua script logitech - start and end a loop when the key is released

77 Views Asked by At

I'm trying to make a script so that when I press a key the loop starts and when I release it the loop ends.

However, the loop keeps running infinitely, even when I release the key.

function OnEvent(event, arg)

if (event == "G_PRESSED" and arg == 1)  then
    
    repeat  

        OutputLogMessage("Loop")
    
        if (event == "G_RELEASED" and arg == 1) then break end

    until (event == "G_RELEASED" and arg == 1)
        
        OutputLogMessage("End Loop")

    end

end
1

There are 1 best solutions below

0
ESkri On
  1. Assign the "Back" action to physical G1 key (in the LGS/GHub GUI).
    ("Back" is the default action for mouse button 4).
  2. Make sure the game ignores mouse button 4 click (in the game control settings).
  3. Set the script:
function OnEvent(event, arg)
  if event == "G_PRESSED" and arg == 1 then  -- G1 key
    repeat  
        OutputLogMessage("Loop")
        Sleep(10)
    until not IsMouseButtonPressed(4)  -- 4 = "back"
    OutputLogMessage("\nEnd Loop\n")
end