【问题标题】:run simultaneous repeat loops Lua Script Logitech GHUB运行同时重复循环 Lua 脚本 Logitech GHUB
【发布时间】:2021-03-16 21:42:08
【问题描述】:

这是我第一次尝试 LUA,所以请耐心等待!

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

此时按钮 3 循环正常工作,但按钮 6 循环并未结束。

理想情况下,我希望在按下和释放各自的按钮时同时工作和停止,AND 让它们 BOTH 在 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

【问题讨论】:

    标签: lua logitech logitech-gaming-software


    【解决方案1】:

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

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

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


    第 2 步。
    转到 GHUB(系统选项卡)
    从 MB#4 中解除“返回”的绑定
    将“Back”绑定到 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)

    【讨论】:

      猜你喜欢
      • 2020-03-12
      • 2021-04-04
      • 2021-09-15
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 2021-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多