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

Logitech G502x原LGS Lua脚本在GHub无法运行的解决咨询

解决方案:LGS Lua脚本适配GHub与G502X鼠标

一、GHub基础配置步骤

  • 打开Logitech G Hub,找到你的G502X鼠标,进入按键分配界面
  • 定位到需要绑定脚本的侧键(对应原LGS中的按键5),点击该按键后选择「分配命令」→「脚本」→「新建脚本」
  • 在脚本编辑器右上角的设置中,勾选持久脚本(Persistent Script),确保脚本能在后台持续运行以保留状态
  • 若不确定侧键对应的arg编号,可在脚本中添加日志打印(见下方代码注释),保存后按下侧键,在GHub的「日志」标签页查看实际数值

二、修改后的适配脚本

local TIMEOUT = 900
local index = 0
local timestamp = 0

function OnEvent(event, arg)
    if event == "MOUSE_BUTTON_PRESSED" then
        -- 取消注释下方行可打印按键事件,用于确认侧键对应的arg值
        -- OutputLogMessage("Event: %s, Arg: %d\n", event, arg)
        if arg == 5 then -- 若日志显示arg不是5,替换为实际数值
            if GetRunningTime() - timestamp >= TIMEOUT then
                index = 0
            end
            index = index + 1
            if index > 3 then
                index = 1
            end
            if index == 1 then
                PressKey("e")
            elseif index == 2 then
                PressKey("w")
            elseif index == 3 then
                PressKey("num1") -- GHub中键名建议使用小写格式
            end
            timestamp = GetRunningTime()
        end
    elseif event == "MOUSE_BUTTON_RELEASED" and arg == 5 then
        if index == 1 then
            ReleaseKey("e")
        elseif index == 2 then
            ReleaseKey("w")
        elseif index == 3 then
            ReleaseKey("num1")
        end
    end
end

关键修改点说明

  • 变量作用域:将原全局变量改为局部变量(local修饰),避免GHub脚本环境中的变量冲突
  • 键名格式:GHub对按键名称的大小写更敏感,将Num1改为小写num1确保兼容性
  • 事件参数:移除了原函数的family参数,GHub的OnEvent函数仅接收event和arg两个参数
  • 状态保留:通过勾选「持久脚本」确保index和timestamp的状态不会在脚本重启后丢失

内容的提问来源于stack exchange,提问作者Loriner De Syrtis

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 02:34:55