Logitech - LGHUB Lua - 无限循环并使用break跳出

大家好,我正在编写lua脚本 ,所有都工作得很好,但是...

当“capslock”处于打开状态并且“MOUSE_BUTTON_PRESSED” >>>> MoveMouseRelative(-52, 0)

这一切都没问题,但我被实现MoveMouseRelative(-52, 0)的无限循环所困扰了2个月

例子:

当“capslock”打开并且“MOUSE_BUTTON_PRESSED”时 我希望MoveMouseRelative(-52, 0)无限循环

当“capslock”关闭时,我希望停止无限循环

这是我的代码:

function OnEvent(event, arg)

        if (event == "PROFILE_ACTIVATED") then
        EnablePrimaryMouseButtonEvents(true)

    elseif event == "PROFILE_DEACTIVATED" then
        ReleaseMouseButton(2)  -- 防止卡住
    end

    if IsKeyLockOn("capslock") then
        recoilx4 = not recoilx4
        spot = not spot
    end

   if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoilx4 ) then
if recoilx4
then
repeat

Sleep(8)
MoveMouseRelative(0, 2.5)
Sleep(8
MoveMouseRelative(-52, 0)
Sleep(8)

            until not IsMouseButtonPressed(1)
        end
    end
end

原文链接 https://stackoverflow.com/questions/70720700

点赞
stackoverflow用户1847592
stackoverflow用户1847592

当 "capslock" 打开且 鼠标按键被按下 的时候,我想要一个无限循环 MoveMouseRelative(-52,0)

而当 "capslock" 关闭时,我想停止这个无限循环

function OnEvent(event, arg)
   if event == "PROFILE_ACTIVATED" then
      EnablePrimaryMouseButtonEvents(true)
   elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsKeyLockOn("capslock") then
      repeat
         Sleep(8)
         MoveMouseRelative(0, 2.5)
         Sleep(8)
         MoveMouseRelative(-52, 0)
         Sleep(8)
      until not IsKeyLockOn("capslock")
   end
end
2022-01-15 11:20:51
stackoverflow用户17989086
stackoverflow用户17989086
使主要鼠标按钮事件可用(true)
function OnEvent(event,arg)
    如果事件 == “MOUSE_BUTTON_PRESSED”并且arg == 4,则
        on = not on
    结束
    如果事件 == “MOUSE_BUTTON_PRESSED”并且arg == 1并on,则    
      重复
         Sleep(8)
         MoveMouseRelative(0, 2.5)
         Sleep(8)
         MoveMouseRelative(-52, 0)
         Sleep(8)
      直到不IsMouseButtonPressed(1)
   结束
end
2022-01-21 02:26:25