luaclicklogitech-gaming-software

My first script is an autoclicker in Logitech G HUB. I just started to get acquainted with Lua


The fact is that this should work when the "Caps Lock" key is turned on and the "Right mouse button" + "Left button" is pressed at the same time. And so that the script starts and finishes working ONLY when both mouse buttons are pressed (aiming and shooting). My problem is that when the right mouse button is clicked, the left mouse button clicks endlessly. My code looks like this:

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if IsKeyLockOn("capslock") then
if IsMouseButtonPressed(3) then
repeat
   PressMouseButton(1)
   Sleep(130)
   ReleaseMouseButton(1)
until not IsMouseButtonPressed(3)
end
end
end

Solution

  • Your script immediately presses the left mouse button after releasing it. This will result in the left mouse button continually being pressed, since there is no time between the mouse button being released and pressed again.

    You should add a second Sleep call to your script so that there is a period of time in which the left mouse button is not pressed:

    EnablePrimaryMouseButtonEvents(true);
    function OnEvent(event, arg)
    if IsKeyLockOn("capslock") then
    if IsMouseButtonPressed(3) then
    repeat
       PressMouseButton(1)
       Sleep(130)
       ReleaseMouseButton(1)
       Sleep(130)
    until not IsMouseButtonPressed(3)
    end
    end
    end
    

    In addition to adding the second Sleep call, you can format your code to use only a single if statement using the and operator. I also re-indented your code, to make it easier to read:

    EnablePrimaryMouseButtonEvents(true);
    function OnEvent(event, arg)
        if IsKeyLockOn("capslock") and IsMouseButtonPressed(3) then
            repeat
                PressMouseButton(1)
                Sleep(130)
                ReleaseMouseButton(1)
                Sleep(130)
            until not IsMouseButtonPressed(3)
        end
    end