Logitech G Hub脚本 - 左键放开后代码有时仍然持续运行

即使我已经放开左键,脚本有时仍会自行点击,该如何停止。

EnablePrimaryMouseButtonEvents(true);

function OnEvent(event, arg)
            if IsMouseButtonPressed(1) then
                repeat
                    Sleep(math.random(50, 75))
                    PressMouseButton(1)
                    Sleep(math.random(50, 75))
                    ReleaseMouseButton(1)
                until not IsMouseButtonPressed(1)
            end
end
点赞
用户1847592
用户1847592

无法同时模拟鼠标左键按下/松开操作并且检测其是否按下/松开。

但是还有一种解决方法:您可以为相同操作添加另一个替代按钮。

例如,如果鼠标左键意味着“开火”,则在游戏中添加按键“P”作为开火的另一种方式。

local key_fire = "P"
EnablePrimaryMouseButtonEvents(true)

function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
      Sleep(math.random(100, 150))
      while IsMouseButtonPressed(1) do
         Sleep(math.random(50, 75))
         PressKey(key_fire)
         Sleep(math.random(50, 75))
         ReleaseKey(key_fire)
      end
   end
end

您可以通过按下鼠标左键进行第一枪射击,然后脚本将在循环中通过程序按下“P”进行第二,第三,...一系列射击。

2020-06-03 03:27:46