I’ve played a bit trying to “autodetect” the host keymap. Here is what I have so far:
C:\dev\uhk-learn-layout>python uhk-learn-layout.py --help
usage: uhk-learn-layout.py [-h] [--debug] [--generate-macro] [--use-altgr] [--macrodelay] [--print-canonical]
[--canonical] [--showmap] [--compact] [--input INPUTFILE]
determine the host layout from the output of the "learn_layout" macro run on a UHK
options:
-h, --help show this help message and exit
--debug show debugging information for developers
--generate-macro generate learn_hostmap macro for UHK Agent. Paste the generated macro code into a
macro command, and bind it to a key. Execute the macro (by tapping the key), and feed
the output into this script to learn the host keymap.
--use-altgr use AltGr combinations in macro (in addition to standard keypress and shift-keypress)
--macrodelay insert delays into the macro (so it runs a bit slower)
--print-canonical print the canoncial string(s) for this keymap
--canonical show the canonical name for this keymap
--showmap show the keyboard layout
--compact show a compact version of the keyboard layout
--input INPUTFILE read input from this file
Generate the macro:
C:\dev\uhk-learn-layout>python uhk-learn-layout.py --generate-macro > macro.txt
C:\dev\uhk-learn-layout>more macro.txt
tapKeySeq keypadPlus keypadPlus keypadPlus keypadPlus keypadPlus space B E G I N space keypadPlus keypadPlus keypadPlus keypadPlus keypadPlus space space enter
tapKeySeq keypadMinus keypadMinus 6 4 keypadMinus graveAccentAndTilde space space enter
tapKeySeq keypadMinus keypadPlus 6 4 keypadMinus LS-graveAccentAndTilde space space enter
tapKeySeq keypadMinus keypadMinus 6 5 keypadMinus 1 space space enter
tapKeySeq keypadMinus keypadPlus 6 5 keypadMinus LS-1 space space enter
tapKeySeq keypadMinus keypadMinus 6 6 keypadMinus 2 space space enter
tapKeySeq keypadMinus keypadPlus 6 6 keypadMinus LS-2 space space enter
...
Using Agent, paste the generated text into a macro (as a macro command), then bind it to a key. I assigned it to Fn-=
.
Next, run the program again on the host, then press Fn-=
so the output of the macro is sent into uhk-learn-layout.py
:
C:\dev\uhk-learn-layout>python uhk-learn-layout.py --canonical --showmap --compact
+++++ BFDUK +++++
... (lots of output) ...
----- FKS -----
Canonical keymap name: US-Colemak
R1: [ `~ ] [ 1! ] [ 2@ ] [ 3# ] [ 4$ ] [ 5% ] [ 6^ ] [ 7& ] [ 8* ] [ 9( ] [ 0) ] [ -_ ] [ =+ ]
R2: [ qQ ] [ wW ] [ fF ] [ pP ] [ gG ] [ jJ ] [ lL ] [ uU ] [ yY ] [ ;: ] [ [{ ] [ ]} ] [ \| ]
R3: [ aA ] [ rR ] [ sS ] [ tT ] [ dD ] [ hH ] [ nN ] [ eE ] [ iI ] [ oO ] [ '" ]
R4: [ -_ ] [ zZ ] [ xX ] [ cC ] [ vV ] [ bB ] [ kK ] [ mM ] [ ,< ] [ .> ] [ /? ]
Now, changing the host keymap (but nothing on the UHK), and run again:
C:\dev\uhk-learn-layout>python uhk-learn-layout.py --canonical --showmap --compact
+++++ BEGIN +++++
... (lots of output) ...
----- END -----
Canonical keymap name: DE
R1: [ ^° ] [ 1! ] [ 2" ] [ 3§ ] [ 4$ ] [ 5% ] [ 6& ] [ 7/ ] [ 8( ] [ 9) ] [ 0= ] [ ß? ] [ ´` ]
R2: [ qQ ] [ wW ] [ eE ] [ rR ] [ tT ] [ zZ ] [ uU ] [ iI ] [ oO ] [ pP ] [ üÜ ] [ +* ] [ #' ]
R3: [ aA ] [ sS ] [ dD ] [ fF ] [ gG ] [ hH ] [ jJ ] [ kK ] [ lL ] [ öÖ ] [ äÄ ]
R4: [ <> ] [ yY ] [ xX ] [ cC ] [ vV ] [ bB ] [ nN ] [ mM ] [ ,; ] [ .: ] [ -_ ]```
Now, let’s do this better, and add AltGr
functionality. Re-generate the macro:
C:\dev\uhk-learn-layout>python uhk-learn-layout.py --generate-macro --use-altgr > macro.txt
Again, paste it into Agent and save the updated macro to the UHK. Now run the detection again (run the script, then press Fn-=
):
C:\dev\uhk-learn-layout>python uhk-learn-layout.py --canonical --showmap --compact
... (lots of output) ...
Canonical keymap name: US-Colemak-International
R1: [ `~~ ] [ 1!¡ ] [ 2@º ] [ 3#ª ] [ 4$¢ ] [ 5%€ ] [ 6^ħ ] [ 7&ð ] [ 8*þ ] [ 9(‘ ] [ 0)’ ] [ -_– ] [ =+× ]
R2: [ qQä ] [ wWå ] [ fFã ] [ pPø ] [ gG˛ ] [ jJđ ] [ lLł ] [ uUú ] [ yYü ] [ ;:ö ] [ [{« ] [ ]}» ] [ \|* ]
R3: [ aAá ] [ rR` ] [ sSß ] [ tT´ ] [ dD¨ ] [ hHˇ ] [ nNñ ] [ eEé ] [ iIí ] [ oOó ] [ '"õ ]
R4: [ -_– ] [ zZæ ] [ xX^ ] [ cCç ] [ vVœ ] [ bB˘ ] [ kK˚ ] [ mM¯ ] [ ,<¸ ] [ .>˙ ] [ /?¿ ]
Or with other keymaps:
Canonical keymap name: DE-International
R1: [ ^° ] [ 1! ] [ 2"² ] [ 3§³ ] [ 4$ ] [ 5% ] [ 6& ] [ 7/{ ] [ 8([ ] [ 9)] ] [ 0=} ] [ ß?\ ] [ ´` ]
R2: [ qQ@ ] [ wW ] [ eE€ ] [ rR ] [ tT ] [ zZ ] [ uU ] [ iI ] [ oO ] [ pP ] [ üÜ ] [ +*~ ] [ #' ]
R3: [ aA ] [ sS ] [ dD ] [ fF ] [ gG ] [ hH ] [ jJ ] [ kK ] [ lL ] [ öÖ ] [ äÄ ]
R4: [ <>| ] [ yY ] [ xX ] [ cC ] [ vV ] [ bB ] [ nN ] [ mMµ ] [ ,; ] [ .: ] [ -_ ]
Canonical keymap name: UK-International
R1: [ `¬¦ ] [ 1! ] [ 2" ] [ 3£ ] [ 4$€ ] [ 5% ] [ 6^ ] [ 7& ] [ 8* ] [ 9( ] [ 0) ] [ -_ ] [ =+ ]
R2: [ qQ ] [ wW ] [ eEé ] [ rR ] [ tT ] [ yY ] [ uUú ] [ iIí ] [ oOó ] [ pP ] [ [{ ] [ ]} ] [ #~\ ]
R3: [ aAá ] [ sS ] [ dD ] [ fF ] [ gG ] [ hH ] [ jJ ] [ kK ] [ lL ] [ ;: ] [ '@ ]
R4: [ \| ] [ zZ ] [ xX ] [ cC ] [ vV ] [ bB ] [ nN ] [ mM ] [ ,< ] [ .> ] [ /? ]
So, this approach works to learn how the host generates characters for each keypress on the UHK. I have (in the python code) now a mapping table that maps keyids to the character generated on the host for the key itself, for shifted, and for AltGr’d versions of the key.
I would like to be able to install such a mapping table into the UHK, so that when I send text from a macro, I can let the keyboard convert the string to produce that string on the host, basically reverse mapping each character to which keyid (potentially with Shift or AltGr modifiers) it needs to activate for that character.
That would make some macros so much more usable, because at the moment, this is what I have to do:
Clearly everyone can see at a glance that this string really means “http://ultimatehackingkeyboard.com”
