Skip to main content
Code formatted
Source Link
Egor Skriptunoff
  • 23.7k
  • 2
  • 37
  • 67
function main()
    -- Define the number of repetitions
    local repetitions = 10

    for i = 1, repetitions do
        -- Mouse left button down
        PressAndReleaseMouseButton(1)  -- Left down
        Sleep(30)                       -- Delay 30 ms

        -- Mouse left button up
        ReleaseMouseButton(1)           -- Left up
        Sleep(5)                        -- Delay 5 ms

        -- Move the mouse
        MoveMouseRelative(0, 2)         -- Move right 0, down 2
    end
end

main()

end

main()

-- Define the number of repetitions

local repetitions = 10

function main() OutputLogMessage("Hold 'LMB' to run the script. Release to stop.\n")

local repetitions = 10

function main()
    OutputLogMessage("Hold 'LMB' to run the script. Release to stop.\n")

    while true do
        -- Check if the left mouse button is held down
        if IsMouseButtonPressed(1) then
            OutputLogMessage("LMB is pressed. Running actions...\n")
            
            for i = 1, repetitions do
                -- Mouse left button down
                PressAndReleaseMouseButton(1)  -- Left down
                Sleep(30)                       -- Delay 30 ms

                -- Mouse left button up
                ReleaseMouseButton(1)           -- Left up
                Sleep(5)                        -- Delay 5 ms

                -- Move the mouse
                MoveMouseRelative(0, 2)         -- Move right 0, down 2
            end
            
            -- Optionally, log that the actions are complete
            OutputLogMessage("Completed %d repetitions.\n", repetitions)
            
            -- Optional: Wait a moment before checking the button again
            Sleep(100)  -- Delay to prevent rapid retriggering
        end

        Sleep(10)  -- Prevent high CPU usage when the button is not pressed
    end
end

main()

end

main()

function main()
-- Define the number of repetitions
local repetitions = 10

for i = 1, repetitions do
    -- Mouse left button down
    PressAndReleaseMouseButton(1)  -- Left down
    Sleep(30)                       -- Delay 30 ms

    -- Mouse left button up
    ReleaseMouseButton(1)           -- Left up
    Sleep(5)                        -- Delay 5 ms

    -- Move the mouse
    MoveMouseRelative(0, 2)         -- Move right 0, down 2
end

end

main()

-- Define the number of repetitions

local repetitions = 10

function main() OutputLogMessage("Hold 'LMB' to run the script. Release to stop.\n")

while true do
    -- Check if the left mouse button is held down
    if IsMouseButtonPressed(1) then
        OutputLogMessage("LMB is pressed. Running actions...\n")
        
        for i = 1, repetitions do
            -- Mouse left button down
            PressAndReleaseMouseButton(1)  -- Left down
            Sleep(30)                       -- Delay 30 ms

            -- Mouse left button up
            ReleaseMouseButton(1)           -- Left up
            Sleep(5)                        -- Delay 5 ms

            -- Move the mouse
            MoveMouseRelative(0, 2)         -- Move right 0, down 2
        end
        
        -- Optionally, log that the actions are complete
        OutputLogMessage("Completed %d repetitions.\n", repetitions)
        
        -- Optional: Wait a moment before checking the button again
        Sleep(100)  -- Delay to prevent rapid retriggering
    end

    Sleep(10)  -- Prevent high CPU usage when the button is not pressed
end

end

main()

function main()
    -- Define the number of repetitions
    local repetitions = 10

    for i = 1, repetitions do
        -- Mouse left button down
        PressAndReleaseMouseButton(1)  -- Left down
        Sleep(30)                       -- Delay 30 ms

        -- Mouse left button up
        ReleaseMouseButton(1)           -- Left up
        Sleep(5)                        -- Delay 5 ms

        -- Move the mouse
        MoveMouseRelative(0, 2)         -- Move right 0, down 2
    end
end

main()
-- Define the number of repetitions
local repetitions = 10

function main()
    OutputLogMessage("Hold 'LMB' to run the script. Release to stop.\n")

    while true do
        -- Check if the left mouse button is held down
        if IsMouseButtonPressed(1) then
            OutputLogMessage("LMB is pressed. Running actions...\n")
            
            for i = 1, repetitions do
                -- Mouse left button down
                PressAndReleaseMouseButton(1)  -- Left down
                Sleep(30)                       -- Delay 30 ms

                -- Mouse left button up
                ReleaseMouseButton(1)           -- Left up
                Sleep(5)                        -- Delay 5 ms

                -- Move the mouse
                MoveMouseRelative(0, 2)         -- Move right 0, down 2
            end
            
            -- Optionally, log that the actions are complete
            OutputLogMessage("Completed %d repetitions.\n", repetitions)
            
            -- Optional: Wait a moment before checking the button again
            Sleep(100)  -- Delay to prevent rapid retriggering
        end

        Sleep(10)  -- Prevent high CPU usage when the button is not pressed
    end
end

main()
added 2 characters in body
Source Link
added 1551 characters in body; edited title
Source Link

The i with the lua script does not work in the logitech g hub program

Tell me how can I wrote a simple codemake my script run indefinitely when I hold down the left mouse button until I release the left mouse button. I tried using chatgpt, but it gave crooked answers and nothing worked.

function OnEventmain(event)
-- Define the number of repetitions
local repetitions = 10

for i = 1, argrepetitions do
    -- Mouse left button down
    PressAndReleaseMouseButton(1)  -- Left down
    ifSleep(30) event == "PROFILE_ACTIVATED" then                   -- Delay 30 ms

    -- Mouse left button up
    ReleaseMouseButton(1)           -- Left up
    Sleep(5)                        -- Delay 5 ms

    -- Move the mouse
    MoveMouseRelative(0, 2)         -- Move right 0, down 2
end

end

main()

And that's what chatgpt gave me:

-- Define the number of repetitions

local repetitions = 10

function main() OutputLogMessage("Hold 'LMB' to run the script. Release to stop.\n")

while true do
    -- Check if the left mouse button is held down
    if IsMouseButtonPressed(1) then
        ClickMouseButtonOutputLogMessage("LMB is pressed. Running actions...\n")
        
        for i = 1, repetitions do
            -- Mouse left button down
            PressAndReleaseMouseButton(1)  -- Left down
            Sleep(500030)                       -- Delay 30 ms

            -- Mouse left button up
            ReleaseMouseButton(1)           -- Left up
            Sleep(5)                        -- Delay 5 ms

            -- Move the mouse
            MoveMouseRelative(0, 2)         -- Move right 0, down 2
        end
        
        -- Optionally, log that the actions are complete
        OutputLogMessage("Completed %d repetitions.\n", repetitions)
        
        -- Optional: Wait a moment before checking the button again
        Sleep(100)  -- Delay to prevent rapid retriggering
    end

    Sleep(10)  -- Prevent high CPU usage when the button is not pressed
end

I open the logitech g hub, select the default desktop profileend

main()

Yes, open scripting thereit works, but for some reason the code does not work. What is the problem?

I didn't try anything,way I just clicked run the script and the line showed thatneed it was loaded without errors. I want him to press the left mouse button every 5 seconds

The lua script does not work in the logitech g hub program

I wrote a simple code

function OnEvent(event, arg) 
    if event == "PROFILE_ACTIVATED" then 
        while true do 
            ClickMouseButton(1) 
            Sleep(5000) 
        end 
    end 
end

I open the logitech g hub, select the default desktop profile, open scripting there, but for some reason the code does not work. What is the problem?

I didn't try anything, I just clicked run the script and the line showed that it was loaded without errors. I want him to press the left mouse button every 5 seconds

i with the lua script in the logitech g hub program

Tell me how can I make my script run indefinitely when I hold down the left mouse button until I release the left mouse button. I tried using chatgpt, but it gave crooked answers and nothing worked.

function main()
-- Define the number of repetitions
local repetitions = 10

for i = 1, repetitions do
    -- Mouse left button down
    PressAndReleaseMouseButton(1)  -- Left down
    Sleep(30)                       -- Delay 30 ms

    -- Mouse left button up
    ReleaseMouseButton(1)           -- Left up
    Sleep(5)                        -- Delay 5 ms

    -- Move the mouse
    MoveMouseRelative(0, 2)         -- Move right 0, down 2
end

end

main()

And that's what chatgpt gave me:

-- Define the number of repetitions

local repetitions = 10

function main() OutputLogMessage("Hold 'LMB' to run the script. Release to stop.\n")

while true do
    -- Check if the left mouse button is held down
    if IsMouseButtonPressed(1) then
        OutputLogMessage("LMB is pressed. Running actions...\n")
        
        for i = 1, repetitions do
            -- Mouse left button down
            PressAndReleaseMouseButton(1)  -- Left down
            Sleep(30)                       -- Delay 30 ms

            -- Mouse left button up
            ReleaseMouseButton(1)           -- Left up
            Sleep(5)                        -- Delay 5 ms

            -- Move the mouse
            MoveMouseRelative(0, 2)         -- Move right 0, down 2
        end
        
        -- Optionally, log that the actions are complete
        OutputLogMessage("Completed %d repetitions.\n", repetitions)
        
        -- Optional: Wait a moment before checking the button again
        Sleep(100)  -- Delay to prevent rapid retriggering
    end

    Sleep(10)  -- Prevent high CPU usage when the button is not pressed
end

end

main()

Yes, it works, but not the way I need it.

Source Link
Loading