0

G13 能够为活动的游戏配置文件设置三个不同的子配置文件,称为 M1、M2、M3 或 MKeystates……基本上允许我根据激活的 Mkey 配置文件将三个命令映射到 G13 上的每个键。

我希望脚本知道 G13 的当前 MKeystate M1、M2、M3 是什么,并在 M1、M2 或 M3 一次仅对一个 MKeyState 执行这些命令,而不是在每个 MKeyState 上执行这些命令。因此,如果子配置文件 1“M1”处于活动状态并且我按下 G4 键,LCD 会显示“前进”,如果子配置文件 2“M2”处于活动状态并且我按下相同的 G4 键,那么 LCD 会显示不同的内容,依此类推。

是否可以为每个子配置文件独立编写脚本?

我尝试在第 27 行之后的部分中添加此内容,但出现语法错误

if ( arg == 4 and MKeyState == 1) then

这是我的代码。我想要它,这样我就可以根据当前活动的子配置文件/ MKeyState 让相同的按键做不同的事情。

isPressed = false;

function OnEvent(event, arg, family)
    -- If a G-Key is pressed
    if event =="G_PRESSED" then
        -- was it G9?
        if arg == 9 then
            ClearLCD ()
            OutputLCDMessage("Auto Run ON", 2000)
            ClearLCD () 
            -- If we're not currently running
            if not isPressed then
                -- we are now
                PressKey("w");
                isPressed = true
            else
            ClearLCD ()
            OutputLCDMessage("Auto Run OFF", 1000)
            ClearLCD ()
                -- stop running
                ReleaseKey("w");
                isPressed = false;
            end
        end
    end

    if ( arg == 4 ) then
            ClearLCD ()
            OutputLCDMessage("FOWARD")
    end

    if ( arg == 7 ) then
            ClearLCD ()
            OutputLCDMessage("MOBI GLASS")
    end

    if ( arg == 1 ) then
            ClearLCD ()
            OutputLCDMessage("PRIMARY WEAPON")
    end
end

4

2 回答 2

0

这似乎工作


-- Auto walk and Display Key Press
isPressed = false

function OnEvent(event, arg, family)
    if event == "G_PRESSED" then
        -- was it G9?
        if arg == 9 then
            ClearLCD()
            OutputLCDMessage("Auto Run ON", 2000)
            ClearLCD()
            -- If we're not currently running
            if not isPressed then
                -- we are now
                PressKey("w")
                isPressed = true
            else
                ClearLCD()
                OutputLCDMessage("Auto Run OFF", 1000)
                ClearLCD()
                -- stop running
                ReleaseKey("w")
                isPressed = false
            end
        end
    end

    local MKeyState = GetMKeyState(family)

    if (arg == 4 and MKeyState == 1) then
        ClearLCD()
        OutputLCDMessage("FOWARD")
    end

    if (arg == 7 and MKeyState == 1) then
        ClearLCD()
        OutputLCDMessage("MOBI GLASS")
    end

    if (arg == 1 and MKeyState == 1) then
        ClearLCD()
        OutputLCDMessage("PRIMARY WEAPON")
    end
end

于 2019-11-26T08:39:15.847 回答
0

不幸的是,您没有提供使用时收到的实际错误消息

if ( arg == 4 and MKeyState == 1) then

并且您没有提供实际尝试使用 M Key 状态的完整代码。

所以我认为MKeyState是这样nil,Lua 抱怨将数字与 nil 值进行比较。

G 系列 Lua API 列出了以下示例

例子

-- Get the current M Key state`

current_mkey = GetMKeyState()`
于 2019-11-26T07:48:17.143 回答