keybow-firmware
keybow-firmware copied to clipboard
Unicode Character Input
Possible solution to #32
This adds snippets for Linux, macOS and Windows that allow the Keybow to input Unicode characters. The snippets use OS-specific keyboard shortcuts, some of which rely on certain system configurations so this feels a bit hack-ish. Hopefully someone can come up with a more user-friendly method.
On macOS the user must be using Unicode Hex Input which can be configured under [System Preferences -> Keyboard -> Input Sources -> + -> Others -> Unicode Hex Input]. The user then has to switch to that input method every time they want to type a Unicode character.
On Windows a registry entry needs to be added under [HKEY_Current_User -> Control Panel -> Input Method]. "EnableHexNumpad" of type string (REG_SZ) needs to be set to 1. The system also has to be rebooted before this method works.
This has been tested on Ubuntu 18.04 LTS, macOS Mojave and Windows 10
Is the "EnableHexNumpad" registry key required for the classic method:
- Hold alt
- Press + on the numpad
- Type the hex unicode value
- Release alt
Yikes- my attempts to actually perform these steps suggest that it is.
Since my cursory research suggests it's impossible to send unicode characters over HID (from device to computer at least) without a custom keyboard layout or driver, this is probably the best we're going to get.
Question about this code since I am playing with this is the intent to use the unicode code point for the hex value? Since this doesn't appear to be working when I try it.
Good question- there's no example for how to use these functions, and I guess the assumption that they use the unicode code point makes sense. But I don't think the logical shift operators will work on a char. Using repl.it attempting to '😄' >> 1' results in failure, and trying string.byte('😄') only gives me the first byte of the 4-byte UTF-8 sequence.
So I guess in this case you'd have to supply the code in the form 0x1F604?
For direct codepoint support I got as far as this, which doesn't work:
emoji = '😄'
emoji_number = 0
for i = 1, #emoji do
local c = emoji:sub(i,i)
emoji_number = (emoji_number + string.byte(c)) * 256
end
print(emoji_number)
Because it basically gives the UTF-8 hex code point converted to an int: 0xF09F9884 == 4036991108 when we need - I think - 0x1F604.
Although that translates to 128516 and if I type that manually on my numpad I get ♦ ... uhm
The input to the functions should be a single UTF-32 encoded character. It's easiest give it in hexadecimal, like this: unicode(0x1f604). By the way, I believe the unicode input on Windows is also in hexadecimal format, so you should be able to type 1f604 to get 😄 (I can't test it right now, but that is what the function does).
In this case it should be possible to use the function I pasted above to convert pasted emoji (and other Unicode characters) directly into the Unicode hexadecimal sequence, since Lua is completely agnostic to character encodings and will let us play with the raw bytes. I'll have to fire up my Keybow and give it a go!