You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

罗技G HUB宏脚本问题:按住右键时无法通过松开左键停止宏

罗技G HUB Lua宏解决方案

问题分析

原代码仅判断右键(Mouse Button 3)是否按住,未监听左键(Mouse Button 1)的释放状态,导致只要右键保持按住,宏就会持续执行,无法通过松开左键停止。

修改后的代码

RC_COUNT = #RC_TABLE
local LastIndex = 1

-- 检查左键是否按下以启动宏
if IsMouseButtonPressed(1) then
    -- 确定起始索引
    local i = LastIndex <= RC_COUNT and LastIndex or 1
    
    -- 循环执行宏步骤,同时检查左键是否保持按下、右键是否保持按住
    while i <= RC_COUNT and IsMouseButtonPressed(1) and IsMouseButtonPressed(3) do
        PressAndReleaseMouseButton(1)
        MoveMouseRelative(RC_TABLE[i].x, RC_TABLE[i].y)
        Sleep(18)
        
        i = i + 1
    end
    
    -- 更新最后执行的索引,用于中断后恢复
    LastIndex = i > RC_COUNT and 1 or i
end

关键调整点

  • 在while循环条件中新增IsMouseButtonPressed(1)检查:只要左键松开,循环立即终止,实现松开左键停止宏的需求
  • 简化起始索引的判断逻辑,用三元表达式替代冗余的if-else
  • 优化LastIndex的更新逻辑,确保中断后再次启动能从上次暂停的位置继续,或循环结束后重置为1

内容的提问来源于stack exchange,提问作者Jim Raynor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 04:39:55