0

Due to an injury, I'm using a G13 to automate work tasks, one of which is entering the current date, in one of a few formats. Using the online compiler here: https://www.tutorialspoint.com/execute_lua_online.php, I was able to figure out how to get and format the date, but what I can't find is an output method that will send the string to Word, Chrome, Notepad, etc. - whatever the active window is. Outputting it to the log or LCD doesn't get it where I need it. Print doesn't output to the active window, and io.write gives the following error: [string "LuaVM"]:11: attempt to index global 'io' (a nil value). Os.date gave a similar error, that's why it's commented out.

My testbed code:

function OnEvent(event, arg)
    OutputLogMessage("event = %s, arg = %s\n", event, arg)
    
    local MKeyState = GetMKeyState("lhc")
    --OutputLogMessage(MKeyState)

    if (event == "G_PRESSED" and arg == 14 and MKeyState == 2) then
        local date = GetDate("%m/%d/%y") --os.date("%m/%d/%y")
        OutputLogMessage(date)
        OutputLCDMessage(date)
        io.write(date)
        --print(os.date("%m/%d/%y"))
    end
end

My testbed output:

event = PROFILE_DEACTIVATED, arg = 0
event = PROFILE_ACTIVATED, arg = 0
event = G_PRESSED, arg = 14
10/22/21[string "LuaVM"]:11: attempt to index global 'io' (a nil value)

event = G_RELEASED, arg = 14

Thanks in advance for any thoughts you might have.

1 Answer 1

1

As far as I can see, one has to use the function PressAndReleaseKey with each character of the string. It is further complicated by the circumstance that this function doesn't take the character itself as an argument, but rather a keyname (see the Table of scancodes and keynames in the API docs). For your date string, this could work (I haven't tested it):

        for c in date:gmatch '.' do
            if c == '/' then
                c = "slash"
            end
            PressAndReleaseKey(c)
        end
Sign up to request clarification or add additional context in comments.

2 Comments

So that being the case, in order to output the date, I'd need it to read the nth character in the string for n = 1 to string_length, determine what key code correlates to that character of the string, then PressAndRelease(that_key)?
Yes, that's what the above snippet is supposed to do. Fortunately, the keynames of the digits are identical to the respective digits, so they don't need translation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.