0

大家好,我想编写一个 Lua 脚本,只要我持有一个特定的键(最好是 G 键,但不是那么重要),它就会重复下面的代码块,并在我释放键时立即停止。作为一种解决方法,我只是让它重复 6 次并停止,但这实际上不是我想要的。

非常感谢!

if event == "G_PRESSED" and arg == 5  then


 for i=1,6 do
if i == 1 then
    end
         PressKey("r")
    Sleep(math.random(50, 100)) 
    ReleaseKey("r")
    Sleep(math.random(2300, 2450)) 
    PressKey("r")
    Sleep(math.random(50, 100)) 
    ReleaseKey("r")
    Sleep(math.random(100, 175)) 
if i == 6 then
    OutputLogMessage("Finished!... ")
end
end
end
4

1 回答 1

0

我假设您正在使用 GHUB 并且同时拥有罗技键盘和罗技鼠标(这两种设备都可以通过 GHUB 进行编程)。

第 1 步。
确保您没有在游戏中使用 MouseButton#4(“返回”)。
如果您在游戏中不使用 MB#4,请跳过“步骤 1”。
如果在游戏中为 MB#4 分配了某些操作,请执行以下操作:

  • 选择您当前未在游戏中使用的键盘按钮
    (假设F12当前未使用该键)
  • 转到 GHUB(鼠标设备,分配部分,KEYS 选项卡);
    绑定F12到您的物理 MB#4
  • 转到游戏选项;
    将旧操作绑定到F12而不是 MB#4

现在,当您按下物理 MB#4 时,游戏会看到F12并激活您的旧动作。


步骤 2.
转到 GHUB(鼠标设备,分配部分)
从 MB#4 取消绑定“返回”(如果您在步骤 1 中尚未完成)


步骤 3.
转到 GHUB(键盘设备、分配部分、系统选项卡)
将“返回”绑定到键 G5


第 4 步
。脚本。

function OnEvent(event, arg)
   if event == "G_PRESSED" and arg == 5 then
      Sleep(10)
      while IsMouseButtonPressed(4) do
         PressKey("r")
         Sleep(math.random(50, 100)) 
         ReleaseKey("r")
         Sleep(math.random(2300, 2450)) 
         PressKey("r")
         Sleep(math.random(50, 100)) 
         ReleaseKey("r")
         Sleep(math.random(100, 175)) 
      end
      OutputLogMessage("Finished!...\n")
   end
end

更新:
切换 G5 的脚本:

local state, prev_btn, prev_rel

local function Sleep2(delay)
   local tm = GetRunningTime() + delay
   while true do
      local time_left = tm - GetRunningTime()
      if time_left <= 0 then
         return
      end
      Sleep(math.min(time_left, 20))
      local curr_btn = IsMouseButtonPressed(4)
      local curr_rel = prev_btn and not curr_btn
      state, prev_btn, prev_rel = state or prev_rel and curr_rel, curr_btn, prev_rel or curr_rel
   end
end

function OnEvent(event, arg)
   if event == "G_PRESSED" and arg == 5 then
      state = not state
      if state then
         Sleep(10)
         state = IsMouseButtonPressed(4)
         if state then
            prev_btn, prev_rel, state = state
            repeat
               PressKey("r")
               Sleep2(math.random(50, 100))
               ReleaseKey("r")
               Sleep2(math.random(2300, 2450))
               PressKey("r")
               Sleep2(math.random(50, 100))
               ReleaseKey("r")
               Sleep2(math.random(100, 175))
            until state
            OutputLogMessage("Finished!...\n")
         end
      end
   end
end
于 2020-12-13T14:44:47.617 回答