LUA 脚本无后座力

我有这段代码,想要在右键按下超过 0.1 秒后激活 repeat 循环,否则不激活,或者在我在 0.1 秒后松开鼠标右键时停止循环,任意一种都行。有什么想法吗?

function OnEvent(event, arg)
    if (event == "PROFILE_ACTIVATED") then
        EnablePrimaryMouseButtonEvents(true)
    end
 if IsKeyLockOn("capslock")then
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 1) then
        if IsMouseButtonPressed(3) then
        Sleep(30)
        repeat
        MoveMouseRelative(-9, 12)
        Sleep(5)
        MoveMouseRelative(9, -9)
        Sleep(5)
        until not IsMouseButtonPressed(1)
        end
      end
    end
  end

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

点赞
stackoverflow用户1847592
stackoverflow用户1847592

我希望在按下右键超过0.1秒后才启动重复循环,否则不要启动。

您可以使用以下代码实现这个目标:

local RMB_tm = math.huge

function OnEvent(event, arg)
   if event == "PROFILE_ACTIVATED" then
      EnablePrimaryMouseButtonEvents(true)
   elseif event == "MOUSE_BUTTON_PRESSED" and arg == 2 then
      RMB_tm = GetRunningTime()
   elseif event == "MOUSE_BUTTON_RELEASED" and arg == 2 then
      RMB_tm = math.huge
   elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1
      and GetRunningTime() - RMB_tm > 100 and IsKeyLockOn("capslock")
   then
      Sleep(30)
      repeat
         MoveMouseRelative(-9, 12)
         Sleep(5)
         MoveMouseRelative(9, -9)
         Sleep(5)
      until not IsMouseButtonPressed(1)
   end
end
2022-01-03 14:40:40