【问题标题】:[Logitec][Lua] I am wondering how to forcefully escape the loop[Logitech][Lua] 我想知道如何强制退出循环
【发布时间】:2021-07-09 16:04:03
【问题描述】:

我很好奇如何在循环中间使用特定键进行转义
而不是在循环结束后转义
我想做的是
启动宏 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)

【问题讨论】:

  • 您不能从外部中止循环for i = 1, 10 do。这就是 Lua 的工作原理。运行时不能执行一些“并行代码”Sleep(200)
  • 从您的问题中不清楚您要解决的真正问题是什么?
  • "abort the loop for i = 1, 10 do from outside." 执行长距离循环时,想知道中间的循环怎么转义
  • 内循环你可以检查IsMouseButtonPressed, IsModifierPressed, IsKeyLockOn

标签: lua logitech logitech-gaming-software


【解决方案1】:

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

if IsMouseButtonPressed(7) then break end

【讨论】:

  • for i = 1, 10 do if IsMouseButtonPressed(1) then OutputLogMessage("pressed\n") break end OutputLogMessage("i = %d\n",i) Sleep(200) end - - 它工作!!!!!!!!!!!!!!!!!!!!!!!!!!!
猜你喜欢
  • 1970-01-01
  • 2011-10-18
  • 1970-01-01
  • 1970-01-01
  • 2019-06-02
  • 1970-01-01
  • 2023-03-08
  • 2021-03-16
  • 2016-03-24
相关资源
最近更新 更多