Logitech/LGHUB Lua – Loop with break

Step 1.
Make sure you’re not using MB#4 (“backward”) in the game.
If some action is assigned to MB#4 in the game, do the following:

  • choose keyboard button you don’t currently use in the game (for example, F12)
  • goto GHUB(KEYS tab); bind F12 to your physical MB#4
  • goto game options; bind the action to F12 instead of MB#4

Now when you press physical MB#4, the game sees F12 and executes your old action.


Step 2.
Goto GHUB(SYSTEM tab); bind “Back” to MB#10


Step 3.
The script.

function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 11 then
      PressMouseButton(1)      -- down LMB
      PressKey("A")            -- down "A"
      repeat
         MoveMouseRelative(5,0)
         Sleep(150)
         MoveMouseRelative(-5,0)
         Sleep(150)
      until IsMouseButtonPressed(4)  -- btn#4 is bound to btn#10
      ReleaseKey("A")          -- up "A"
      ReleaseMouseButton(1)    -- up LMB
   end
end

How does it work:
When you press MB#11, the loop starts.
When you later press MB#10, IsMouseButtonPressed() sees that button#4 is pressed, and the loop exits.

Leave a Comment