Lua脚本Logitech GHUB的同时循环循环

这是我第一次尝试LUA,所以请理解我!

我正在尝试将我想要同时循环的几个函数组合起来,但我只能让它们按顺序运行。 理想情况下,绑定到鼠标按钮6的函数将在按下时启动并在释放时停止(当前根本不停止!!)。另外,鼠标按钮3上的函数在按下时运行并在释放时停止(这个确实停止了)。

目前,按钮3的循环按预期工作,但按钮6的循环不会结束。

理想情况下,我希望两个都能在它们各自的按钮按下和释放上工作和停止,并且当3和6都被一起按下时,它们都能同时运行。

这可以做到吗?如果可以,我需要改变什么才能实现这一点?

EnablePrimaryMouseButtonEvents(true);

function OnEvent(event, arg)
    if event == "MOUSE_BUTTON_PRESSED" and arg == 6 then
        repeat
            MoveMouseRelative(300,0)
                Sleep(150)
                MoveMouseRelative(-300,0)
                Sleep(1500)
    until event == "MOUSE_BUTTON_RELEASED" and arg == 6
    elseif IsMouseButtonPressed(3) then
        repeat
            MoveMouseRelative(0,300)
            Sleep(1000)
        until not IsMouseButtonPressed(3)
    end
end

提前感谢:D

点赞
用户1847592
用户1847592

步骤 1.

确保在游戏中没有使用 MB#4(“返回”)。

如果游戏中没有使用 MB#4,只需跳过“步骤 1”。

如果将某些操作分配给游戏中的 MB#4,请执行以下操作:

  • 选择游戏中未使用的键盘按钮(例如,F12
  • 转到 GHUB(“键”选项卡);将 F12 绑定到物理的 MB#4
  • 转到游戏选项;将操作绑定到 F12 而不是 MB#4

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


步骤 2.

转到 GHUB(“系统”选项卡)

从 MB#4 中解除“返回”

将“返回”绑定到 MB#6


步骤 3.

脚本。

local all_buttons = {
   [4] = {  -- 鼠标按钮#6
      {time=0,   x=50 }, -- 在时间0时向右移动鼠标50像素
      {time=150, x=-50}, -- 在时间150时将鼠标向左移动50像素
      {time=150+1500},   -- 在时间150 + 1500时重复循环
   },
   [3] = {  -- 右键鼠标按钮
      {time=0, y=50},  -- 在0时移动鼠标向下50像素
      {time=1000},     -- 在1000时间时重复循环
   }
}

function OnEvent(event, arg)
   if event == "PROFILE_ACTIVATED" then
      EnablePrimaryMouseButtonEvents(true)
   elseif event == "MOUSE_BUTTON_PRESSED" then
      repeat
         Sleep(10)
         local tm = GetRunningTime()
         local some_loop_is_active
         for btn_no, info in pairs(all_buttons) do
            if not info.started and IsMouseButtonPressed(btn_no) then
               info.started = tm
               info.next_step = 1
            end
            some_loop_is_active = some_loop_is_active or info.started
            local next_action = info[info.next_step]
            if info.started and tm - info.started >= next_action.time then
               info.next_step = info.next_step + 1
               local x, y = next_action.x, next_action.y
               if x or y then
                  x, y = x or 0, y or 0
                  local sx, sy = x < 0 and -1 or 1, y < 0 and -1 or 1
                  x, y = x*sx, y*sy
                  while x > 0 or y > 0 do
                     local px, py = x < 127 and x or 127, y < 127 and y or 127
                     MoveMouseRelative(px*sx, py*sy)
                     x, y = x-px, y-py
                  end
               else
                  info.started = nil
               end
            end
         end
      until not some_loop_is_active
   end
end

您应该知道 MoveMouseRelative()最多只能移动 127 像素。

要移动鼠标光标 300 像素,应调用它 3 次:

MoveMouseRelative(0,100);MoveMouseRelative(0,100);MoveMouseRelative(0,100)

2020-12-05 08:24:30