0
votes

The G13 has the ability to set three different sub profiles called M1,M2,M3 or MKeystates for the active game profile...basically allowing me to map three commands to each key on the G13 depending on which Mkey profile is active.

I would like the script to know what is the current MKeystate M1,M2,M3 of the G13 and execute the these commands on only one MKeyState at a time M1, M2 or M3 rather then work across every one. So if sub profile 1 "M1" is active and I press the G4 key the LCD says "Forward" and if the sub profile 2 "M2" is active and I press the same G4 key then LCD would show something different and so on.

Is it possible to script for each sub profile independently?

Ive tried adding this in the sections after line 27 but I get a syntax error

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

Here is my code. I want it so I can have the same key press do different things depending on the current active sub profile / 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

2

2 Answers

0
votes

Unfortunately you did not provide the actual error message you get when you use

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

and you did not provide the full code where you're actually trying to use the M Key states.

So I presume that MKeyState is nil and Lua complains about comparing a number with a nil value.

The G-Series Lua API lists the following example

Example

-- Get the current M Key state`

current_mkey = GetMKeyState()`
0
votes

This seems to be working


-- 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