首页 > 解决方案 > 运行同时重复循环 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

先谢谢了

标签: lualogitechlogitech-gaming-software

解决方案


第 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] = {  -- mouse button #6
      {time=0,   x=50 }, -- at time 0 move mouse right 50 pixels
      {time=150, x=-50}, -- at time 150 move mouse left 50 pixels
      {time=150+1500},   -- at time 150+1500 repeat the loop
   },
   [3] = {  -- right mouse button
      {time=0, y=50},  -- at time 0 move mouse down 50 pixels
      {time=1000},     -- at time 1000 repeat the loop
   }
}

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)


推荐阅读