0

我试图让下面的代码在按下或按住鼠标按钮 1 时只执行一次 MoveMouseRelative 函数。我试过删除“重复”行,但它破坏了代码。当前,当激活并按住鼠标 1 时,光标会不断向下拖动。

function OnEvent(event, arg)
    OutputLogMessage("event = %s, arg = %d\n", event, arg)
    if (event == "PROFILE_ACTIVATED") then
        EnablePrimaryMouseButtonEvents(true)
    elseif event == "PROFILE_DEACTIVATED" then
        ReleaseMouseButton(2)  -- to prevent it from being stuck on
    end
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
        recoilx2 = not recoilx2
        spot = not spot
    end
   if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoilx2) then
        if recoilx2 then
            repeat
                --Sleep(35)
                Sleep(5)
                MoveMouseRelative(0, 3)
            until not IsMouseButtonPressed(1)
        end
    end
4

1 回答 1

0

目标:用于执行以下任务的罗技鼠标 Lua 脚本:
当鼠标按钮 5 被“激活”时:
-每 1000 毫秒左击一次(两次拍摄之间的时间),
-并且每 1000 毫秒向下拉一次鼠标。
因此,如果我按住鼠标左键,它会连续射击,但只有在射击时才会拉下

选择一个您在游戏中从未使用过的键盘按钮并将其设置为开枪的唯一方式,该键将用于以编程方式开火。
我假设键是P,但您可以选择任何其他按钮:“f12”、“退格”、“num9”、...
游戏必须在按下鼠标左键时什么都不做。

local fire_button = "P"

function OnEvent(event, arg)
   OutputLogMessage("event = %s, arg = %d\n", event, arg)
   if event == "PROFILE_ACTIVATED" then
      EnablePrimaryMouseButtonEvents(true)
   elseif event == "PROFILE_DEACTIVATED" then
      -- to prevent mouse buttons from being stuck on
      for j = 1, 5 do ReleaseMouseButton(j) end
   end
   if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
      recoilx2 = not recoilx2
   end
   if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
      PressKey(fire_button)
      Sleep(50)
      ReleaseKey(fire_button)
      if recoilx2 then
         while IsMouseButtonPressed(1) do
            MoveMouseRelative(0, 25)
            local next_shot_time = GetRunningTime() + 1000
            local LMB
            repeat
               Sleep(50)
               LMB = IsMouseButtonPressed(1)
            until not LMB or GetRunningTime() >= next_shot_time
            if LMB then
               PressKey(fire_button)
               Sleep(50)
               ReleaseKey(fire_button)
            end
         end
      end
   end
end
于 2020-03-04T05:46:00.663 回答