如何在释放 LMB 时停止重复的动作列表

How to stop a repeated list of actions when releasing LMB

我有一个操作列表如下:

PressAndReleaseKey("f13") -- Action 1
Sleep(200)
PressAndReleaseKey("f13") -- Action 2
Sleep(200)
PressKey("f13") -- Action 3
Sleep(400)
ReleaseKey("f13") -- Action 4
Sleep(200)

我想在按下 LMB 时重复这些操作,并在释放 LMB 时取消所有操作

例如:

所以请帮助我,这是我目前的脚本:

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)

   if event == "MOUSE_BUTTON_PRESSED" and arg == 1  then
        if IsMouseButtonPressed(1) then
            repeat
                PressAndReleaseKey("f13") -- Action 1
                Sleep(200)
                PressAndReleaseKey("f13") -- Action 2
                Sleep(200)
                PressKey("f13") -- Action 3
                Sleep(400)
                ReleaseKey("f13") -- Action 4
                Sleep(200)
            until not IsMouseButtonPressed(1)   
        end     
    end
end

(选项 2)如果这样的 repeat 不可能 => 还有另一个更手动的选项,如 local,最多列出 100 次操作

您无法取消任何操作。您可以执行或不执行。一旦触发就无法停止。

如果您想在操作 1 和操作 2 之后停止执行,您必须在操作 2 之后检查按钮状态,并且只有在按钮仍被按下时才执行操作 3。当前,您仅在执行完所有操作后才检查按钮。

if not IsMouseButtonPressed(1) then break end 放在任何操作之前,以便在按下按钮时不会执行。