[罗技][Lua]我想知道如何强行跳出循环

[Logitec][Lua] I am wondering how to forcefully escape the loop

我很好奇如何在循环中间使用特定的键进行转义
而不是在循环结束后转义
我想做的是
启动宏 i = 1 i = 2 i = 3 i = 4 中止(当我按 arg 7 时) .

完整脚本:

local isMacroRunning = false

co = coroutine.create(function()
    while true do
        if not isMacroRunning then break end
        MoveMouseRelative (5, 0)
        Sleep(150)
        MoveMouseRelative (-5, 0)
        Sleep(150)
        OutputLogMessage("Break\n")
        coroutine.yield()
    end
end)

function OnEvent(event, arg)
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 8) then
        isMacroRunning = true
        RunMacro()
    elseif(event == "MOUSE_BUTTON_PRESSED" and arg == 7 and isMacroRunning) then
        isMacroRunning = false
        RunMacro()
    end
end

function RunMacro()
    if isMacroRunning then
        coroutine.resume(co)
        OutputLogMessage("Start Macro\n")
        for i = 1, 10 do
            OutputLogMessage("i = %d\n",i)
            Sleep(200)
        end
    else
        OutputLogMessage("Aborted\n")
    end
end

coroutine.resume(co)

为什么不检查按钮是否在循环内按下?

if IsMouseButtonPressed(7) then break end