罗技G213键盘G-ALT宏脚本失效原因排查及适配方案咨询
适配罗技G213键盘的宏脚本修复方案
失效原因
- 罗技G105的G键触发专属的
G_PRESSED事件,而G213的G键默认映射为F1-F12,触发的是通用KEY_PRESSED事件,原脚本仅监听G_PRESSED,因此无法响应G键操作。 - 若罗技G HUB中G键被设置为执行预设宏,脚本会无法捕获按键事件,必须确保G键处于“未分配”或“按原样传递按键”状态。
修复步骤
- G HUB配置调整:打开罗技G HUB,将G1/G2/G3键设置为未分配(或选择“按原样传递F1/F2/F3”),避免系统优先处理G键的默认映射。
- 脚本逻辑修改:替换事件监听类型,将原脚本中的
G_PRESSED改为KEY_PRESSED,并匹配对应的F键参数(F1对应arg=112,F2对应arg=113,F3对应arg=114,也可直接通过键名判断)。
修改后的完整脚本
local function interruptable_sleep(delay) local tm = GetRunningTime() + delay local t repeat if IsKeyLockOn("scrolllock") then return true end t = tm - GetRunningTime() if t > 0 then Sleep(math.min(t, 100)) end until t <= 0 end function OnEvent(event, arg) local exit local macros -- 监听F1/F2/F3按键(对应G1/G2/G3)+ Alt组合 if event == "KEY_PRESSED" then -- Alt + G3(对应F3) if arg == 114 and IsModifierPressed("lalt") then macros = { {macro = "Pet1", sleep_macro = 7100}, {macro = "Pop", sleep_macro = 300}, {macro = "Rush", sleep_macro = 600}, {macro = "MASS", sleep_macro = 6000}, {macro = "Pet2", sleep_macro = 6300}, {macro = "Pop", sleep_macro = 300}, {macro = "Rush", sleep_macro = 600}, {macro = "MASS", sleep_macro = 6000}, {macro = "Pet3", sleep_macro = 5800}, {macro = "Pop", sleep_macro = 300}, {macro = "Rush", sleep_macro = 600}, {macro = "MASS", sleep_macro = 6000} } -- Alt + G2(对应F2) elseif arg == 113 and IsModifierPressed("lalt") then macros = { {macro = "Pop", sleep_macro = 300}, {macro = "Rush", sleep_macro = 600}, {macro = "IOS", sleep_macro = 8200}, {macro = "Pet2", sleep_macro = 3600}, {macro = "Pop", sleep_macro = 300}, {macro = "Rush", sleep_macro = 600}, {macro = "IOS", sleep_macro = 8200}, {macro = "Pet4", sleep_macro = 3600}, } -- Alt + G1(对应F1) elseif arg == 112 and IsModifierPressed("lalt") then macros = { {macro = "Pop", sleep_macro = 300}, {macro = "Rush", sleep_macro = 600}, {macro = "MASS", sleep_macro = 6000}, {macro = "Pet2", sleep_macro = 6500}, {macro = "Pop", sleep_macro = 300}, {macro = "Rush", sleep_macro = 600}, {macro = "MASS", sleep_macro = 6000}, {macro = "Pet4", sleep_macro = 6500}, } end end if macros then repeat exit = false for _, phase in ipairs(macros) do PlayMacro(phase.macro) exit = interruptable_sleep(phase.sleep_macro) AbortMacro() if exit then break end end until exit Sleep(250) PressAndReleaseKey("scrolllock") end end
补充说明
如果通过键名判断更直观,也可以将arg == 112替换为GetKeyName(arg) == "F1",同理F2/F3,效果完全一致。
内容的提问来源于stack exchange,提问作者Cipri
相关产品推荐
相关产品推荐

