-1

The loop in LGS, if I release M4, it will execute the entire process before stopping. Can someone provide me with a Lua?

When I press and hold M4: key P is pressed → 100ms delay → M1 is clicked → 25ms delay → key P is released (every 350ms cycle). When I release M4, it immediately stops, rather than executing the entire process before stopping. When I press and hold M4 again, the command starts from scratch instead of continuing halfway through the previous stop.

ESkri
  • 1,461
  • 1
  • 1
  • 8
kql778
  • 1
  • 1

1 Answers1

0

You need "interruptable sleep" function which is polling M4 button.

local exit

local function InterruptableSleep(ms)
   if not exit then
      local tm = GetRunningTime() + ms
      repeat
         Sleep(5)
         exit = not IsMouseButtonPressed(4) 
      until exit or GetRunningTime() >= tm
   end
   return exit
end

function OnEvent(event, arg)
   if event == 'MOUSE_BUTTON_PRESSED' and arg == 4 then
      exit = false
      repeat
         PressKey("P")
         if not InterruptableSleep(100) then
            PressAndReleaseMouseButton(1)
            InterruptableSleep(25)
         end
         ReleaseKey("P")
         InterruptableSleep(350) 
      until exit
   end
end
ESkri
  • 1,461
  • 1
  • 1
  • 8