Keybow - Running a desktop shortcut

Hi All, please can you help a noob?!!

I got my Keybow all assembled and up and running in it’s default configuration and it works fine.

I then followed the simple tutorial to get key 0 to open the Run window and run cmd.exe, this code:

function handle_key_00(pressed)
    if pressed then
        keybow.set_modifier(keybow.LEFT_META, keybow.KEY_DOWN)
        keybow.tap_key("r", pressed)
        keybow.set_modifier(keybow.LEFT_META, keybow.KEY_UP)
		keybow.sleep(500)
		keybow.text("cmd.exe")
		keybow.tap_enter()
    end
end

As expected it works, it also works when I replace cmd.exe with notepad.exe. All the other keys also work as per the rest of the default.

My problems start when I replace the cmd.exe with the path of the shortcut I want to run, i,e,:

function handle_key_00(pressed)
    if pressed then
        keybow.set_modifier(keybow.LEFT_META, keybow.KEY_DOWN)
        keybow.tap_key("r", pressed)
        keybow.set_modifier(keybow.LEFT_META, keybow.KEY_UP)
		keybow.sleep(500)
		keybow.text("C:\xxxxxt\xxxxxx.xxxx")
		keybow.tap_enter()
    end
end

None of the keys then work, not this key or any of the other keys that I haven’t changed the code of!!

The Keybow seems to be on as the LED light pattern runs, whichever pattern I change it too!

I can’t understand why it just stops, I expected it to “type” the shortcut path in to the run box but nothing happens!

I know it’s obviously something I’m doing wrong.Thanks in advance.

You should check your Lua syntax. You’ve just run into the exciting world of escape characters.

Go to: https://repl.it/languages/lua

And try inputting: print("C:\xxxxxt\xxxxxx.xxxx")

And running it.

Since \ denotes that the next character is some kind of special character in a Lua string, you need to escape the escape character, making your string:

"C:\\xxxxxt\\xxxxxx.xxxx"

Valid escape sequences include things like \n for newline, which otherwise can’t be represented in a string without breaking syntax.

Thank you for your help gadgetoid, I understand it better now.

However, I used \ but now I get a # instead of a \ and sometimes it reverses the case of the letters in the string, i.e. I either get C#xxxxxx#xxxxxx.xxxx or c#XXXXX#XXXXXX.XXXX

I tried making changes it the keybow.lua file but I’m still having no luck!!

I suspect the # and / different may be something to do with keyboard region. Do you know what region you’ve got your keyboard set to?

The upper/lower case problem might be a bug, I’ll have to rig up a test for that.

Well it’s clearly not region related.

I tried "notepad.exe C:\Windows\System32\Drivers\etc\hosts"

And seem to have got `“notepad.exe C:\WINDOWS\system32#Windows#System32#Drivers#etc#hosts”

Looking into it!

Edit:

What it’s actually typing is notepad.exe C:#Windows#System32#Drivers#etc#hosts, which is sensible. I believe I’ve found a small bug with the shift state where the shift key should probably be released after the letter key is released.

I’ve clearly mapped # and \ incorrectly, though! Back to the keycodes tables.

Bit of a monkey-patch, but it should get you up and running for now. Open up keybow.lua and substitute keybow.set_key for this:

function keybow.set_key(key, pressed)
    if type(key) == "string" then
        local hid_code = nil
        local shifted = true
        if key == "\\" then
            hid_code = 0x64
            shifted = false
        elseif key == "|" then
            hid_code = 0x64
            shifted = true
        elseif key == "#" then
            hid_code = 0x32
            shifted = false
        elseif key == "~" then
            hid_code = 0x32
            shifted = true
        else
            hid_code = SHIFTED_KEYCODES:find(key, 1, true)
            if hid_code == nil then
                hid_code = KEYCODES:find(key, 1, true)
                shifted = false
            end
            hid_code = hid_code + 3
        end

        if not (hid_code == nil) then
            if shifted and pressed then keybow.set_modifier(keybow.LEFT_SHIFT, true) end
            keybow_set_key(hid_code, pressed)
            if shifted and not pressed then keybow.set_modifier(keybow.LEFT_SHIFT, false) end
        end

    else -- already a key code
        keybow_set_key(key, pressed)
    end
end

This catches \ | # ~ and treats them as special cases for now, in addition to (hopefully) fixing the upper/lowercase bug.

You are a star!! That seems to have worked!!

Thank you so much.

No problem! I’ve got to figure out how to add it into Keybow proper without breaking US-English now :D

Was this ever put in to the released version or we still have to mode the key.lua?

After some digging around more I found out you can do the following:

Print([[C:\Program Files (x86)\Microsoft Office\Office16\WINWORD.exe]])

works So I wounder if that would work for the test input in keybow. [[ ]] is used to be able to interpret (\ backslash) as just a character.