smz
smz

Reputation: 1

Logitech lua macro

i'm not so sure how to proceed to this to work, tried some stuff but didn't manage to make it work.

I want it to work like mouse 4 do that one macro and mouse 5 do the other. I'm using that fast sleep cause windows update made logitech macros really slow.

just a little example

do
    local function busyloop(final_ctr)
       final_ctr = final_ctr - final_ctr%1
       local ctr, prev_ms, ms0, ctr0 = 0
       while ctr ~= final_ctr do
          local ms = GetRunningTime()
          if prev_ms and ms ~= prev_ms then
             if not ms0 then
                ms0, ctr0 = ms, ctr
             elseif final_ctr < 0 and ms - ms0 > 500 then
                return (ctr - ctr0) / (ms - ms0)
             end
          end
          prev_ms = ms
          ctr = ctr + 1
       end
    end
    local coefficient = busyloop(-1)
    function FastSleep(ms)
       return busyloop(ms * coefficient)
    end
 end
 
 function OnEvent(event, arg)
     if (event == "MOUSE_BUTTON_PRESSED" and arg == 4)then
         repeat
         PressMouseButton(1)
         MoveMouseRelative(-1,1)
         FastSleep(1)
         ReleaseMouseButton(1)
         until not IsMouseButtonPressed(4)
 
if (event == "MOUSE_BUTTON_PRESSED" and arg == 5)then
         repeat
         PressMouseButton(2)
         MoveMouseRelative(-2,2)
         FastSleep(2)
         ReleaseMouseButton(2)
         until not IsMouseButtonPressed(5)
 
        end
         end
   end

didnt manage to find a way around it, tried many ways.

Upvotes: 0

Views: 1684

Answers (1)

ESkri
ESkri

Reputation: 1908

You should write the code with correct indentation to make correct statement nesting

function OnEvent(event, arg)
    if event == "MOUSE_BUTTON_PRESSED" and arg == 4 then
        repeat
            PressMouseButton(1)
            MoveMouseRelative(-1,1)
            FastSleep(2.5)
            ReleaseMouseButton(1)
        until not IsMouseButtonPressed(4)
    elseif event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
        repeat
            PressMouseButton(1)
            MoveMouseRelative(-2,2)
            FastSleep(2.5)
            ReleaseMouseButton(1)
        until not IsMouseButtonPressed(5)
    end
end

Upvotes: 1

Related Questions