Logitech G-Hub鼠标宏脚本调整求助:两种触发模式需求
Logitech G-Hub 宏脚本问题修正方案
模式一:按住鼠标8键持续执行,松开停止
原脚本核心问题是 PressKey("q","s") 和 ReleaseKey("q","s") 写法错误——这两个函数一次仅支持传入一个按键参数,同时传两个会导致脚本执行异常,因此只触发了一次循环就终止。
修正后的脚本:
EnablePrimaryMouseButtonEvents(true) function OnEvent(event, arg) if event == "MOUSE_BUTTON_PRESSED" and arg == 8 then repeat -- 按下左键 PressMouseButton(1) Sleep(math.random(70, 120)) -- 分别按下q、s键(拆分调用避免参数错误) PressKey("q") PressKey("s") Sleep(math.random(70, 120)) -- 释放左键 ReleaseMouseButton(1) -- 分别释放q、s键 ReleaseKey("q") ReleaseKey("s") -- 可选:循环间隔随机休眠,避免执行过于频繁 Sleep(math.random(30, 50)) until not IsMouseButtonPressed(8) -- 松开8键时停止循环 end end
模式二:点击鼠标8键切换启停(轻点一次启动,再点一次停止)
通过全局变量记录运行状态,每次点击8键翻转状态实现启停切换:
EnablePrimaryMouseButtonEvents(true) -- 全局变量:标记宏是否正在运行 local is_running = false function OnEvent(event, arg) if event == "MOUSE_BUTTON_PRESSED" and arg == 8 then is_running = not is_running -- 切换为运行状态时启动循环 while is_running do -- 按下左键 PressMouseButton(1) Sleep(math.random(70, 120)) -- 分别按下q、s键 PressKey("q") PressKey("s") Sleep(math.random(70, 120)) -- 释放左键 ReleaseMouseButton(1) -- 分别释放q、s键 ReleaseKey("q") ReleaseKey("s") -- 可选:循环间隔随机休眠 Sleep(math.random(30, 50)) -- 检查状态,确保停止指令能及时生效 if not is_running then break end end end end
内容的提问来源于stack exchange,提问作者전주뽀짝
相关产品推荐
相关产品推荐

