为脚本添加冷却时间

时间:2020-06-08 10:00:03

标签: lua logitech-gaming-software

function OnEvent(event, arg)

EnablePrimaryMouseButtonEvents(1)

    if (event == "MOUSE_BUTTON_PRESSED" and arg == 1) do
        PressAndReleaseKey("lalt")
            Sleep(15000)
end
end

我有这个脚本,当我单击鼠标左键时可以按Alt键,但是我不希望它每次都发生。

我想添加15秒的“冷却时间”,以使脚本不会在15秒内重复。

我添加的睡眠功能在PressAndReleaseKey之前运行。

如何交换这两个?

1 个答案:

答案 0 :(得分:0)

local prev_time = -math.huge

function OnEvent(event, arg)
   if event == "PROFILE_ACTIVATED" then
      EnablePrimaryMouseButtonEvents(true)
   elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
      local this_time = GetRunningTime()
      if this_time - prev_time > 15000 then
         prev_time = this_time
         PressKey("lalt")
         Sleep(50)
         ReleaseKey("lalt")
      end
   end
end