user16379288
user16379288

Reputation: 1

LOGITECH GHUB LUA: SetMKeyState

I would like to use the SetMKeyState(...) and GetMKeyState(...) functions available in the Logitech LUA scripting api, to write some macros.

I am using Windows 10 and the latest version of Logitech GHUB (I can't use LGS for various reasons). On my keyboard, Logitech G815, it seems that any call to SetMKeyState(...) from a LUA macro does not do anything. While the GetMKeyState(...) seems to correctly return the current MKey state. I have read the docs related to these two functions in the "G-series Lua API V8.45" documentation and it looks like I am using them correctly.

For example, the following LUA script should switch the MKey state between M1/M2/M3 using the G1 key, but actually does not do anything (although the code is executed, as the debug log lines appear):

function OnEvent(event, arg)
  if (event == "G_PRESSED" and arg == 1) then
    currentState = GetMKeyState("kb")
    OutputLogMessage("Current MKey state: %d\n", currentState)
    newState = currentState + 1
    if newState == 4 then
      newState = 1
    end
    OutputLogMessage("Setting new MKey state: %d\n", newState )
    SetMKeyState(newState , "kb");
  end
end

Am I doing anything wrong here ?

If it is expected that the SetMKeyState(...) function is not supported on the Logitech G815, then which keyboard model would correctly support the SetMKeyState(...) function to change the MKey state ?

Upvotes: 0

Views: 1394

Answers (1)

kay27
kay27

Reputation: 909

It's not actually an answer, just a suggestion, but IDK the way to paste the code in comments, so hope you will forgive me :) There is a reference code in API doc:

-- Set the current M Key state to M1 when G1 is pressed
function OnEvent(event, arg)
    if (event == "G_PRESSED" and arg == 1) then
        SetMkeyState(1);
    end
end

If I were you I'd get started from the check if it works or not as it is, without any change.

Then, step by step:

  • add debug messages;
  • recheck;
  • try to set it to 2 instead of 1;
  • try to set it to 3;
  • try to read and print current state, before and after the operation, considering this remark from API doc: "Calling GetMKeyState immediately afterwards, will likely return the previous state. Use the OnEvent handler to determine when the operation has completed."

Upvotes: 0

Related Questions