1
votes

I am trying to make a LGS macro that repeats pressing the "P" key, while I hold a mouse button. Since I would like this macro to use random sleep intervals between each keypress, I can't use the standard Logitech GUI for that, since this only supports standard intervals. Therefore, it seems I need to use a Lua script to achieve this.

After some research I have come across a script in this forum and modified it that from my understanding should work, but unfortunately doesn't. "My" script only repeats the actions once when I press the mouse button, instead of continuously looping.

I have no idea about programming so please do not feel burdened to stay close to my script if you see a better implementation, even the sleep time parameters are random and I have no idea if those may simulate human behavior.

EnablePrimaryMouseButtonEvents(true)

function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 6 then
      repeat
         PressKey("P")
         Sleep(math.random(27, 43)) 
         ReleaseKey("p") 
         Sleep(math.random(29, 36)) 
      until IsMouseButtonPressed(6)
   end
end
1
Thank you so much Egor, that did the trick. I can't believe that the number was the issue, haha. Just for understanding, does "until (event == "MOUSE_BUTTON_PRESSED" and arg == 6) == false" make any sense?G-T
arg == 6 does make sense, but IsMouseButtonPressed(6) does not.Egor Skriptunoff
until (event == "MOUSE_BUTTON_PRESSED" and arg == 6) == false this will not work for any arg. When inside a loop, you're staying in the same event. To change event, you must exit OnEventEgor Skriptunoff

1 Answers

0
votes

Egor Skriptunoff's comment:

Only first 5 buttons are available for IsMouseButtonPressed(). And the condition in the until statement should look like until not IsMouseButtonPressed(5) if you want to stop the loop on mouse button release.