Thanks to Crafters hanging out on the IRC channel, I learned about Kanata for remapping keys. I use a split mechanical keyboard and miss the conveniences of layers and homerow mods while on my laptop. So far, Kanata has been an excellent option for me.
To continue with my goal of creating more approachable guides to technical topics, I wrote an article on Starting using Kanata to remap any keyboard, with a focus on not only what to do but why we’re doing it and with some background around what these different pieces of configuration mean. My hope is to simplify the first steps for someone without a programming/IT background.
Let me know if you have any feedback or questions!
I tried to use Kanata last night. The config language of both Kanata and KMonad are confusing, not because of the Lisp, but because of having to completely map your keyboard in a table. All I want to do is map AltGr h to ẖ.
To make it more complicated, I’m on a ThinkPad X200 with a UK keyboard.
@Kolev With Kanata you don’t need to map the whole keyboard (not sure about Kmonad), you only put the keys in defsrc that you want to manipulate. See my example here, the order of the keys don’t matter either, they just need to be consistent once you define them in defsrc.
The link above also links to all the keycodes that can be used. You could use AltGr to activate a layer that maps h to ẖ, one way to do it. Or you can just map tap-hold h to produce h on tap and ẖ on hold. I’ll whip up a config to share when I get home.
Attached is the config I’m using to type this. kanata.kbd (1.5 KB)
2024-04-22T16:47:45.852443261-05:00 [ERROR] Failed to open the output uinput device. Make sure you've added the user executing kanata to the `uinput` group
2024-04-22T16:47:45.853334361-05:00 [ERROR] Permission denied (os error 13)
I tried adding my user to the group.
usermod: group 'uinput' does not exist
EDIT: Followed “Permissions” but still got errors both with and without sudo.
@Kolev were you able to do all 5 steps of the permissions section ? Are you still getting a uinput doesn’t exist error? What does the output of groups show? Maybe try a reboot if you don’t see uinput.
were you able to do all 5 steps of the permissions section ?
Yes.
Are you still getting a uinput doesn’t exist error?
Yes.
What does the output of groups show?
Looks like I’ll have to reboot.
caleb@hermes:~$ groups
caleb adm cdrom sudo dip plugdev lpadmin sambashare
Errors:
caleb@hermes:~$ kanata
2024-04-22T18:30:47.323460475-05:00 [INFO] kanata v1.5.0 starting
2024-04-22T18:30:47.323496413-05:00 [INFO] You may forcefully exit kanata by pressing lctl+spc+esc at any time. These keys refer to defsrc input, meaning BEFORE kanata remaps keys.
2024-04-22T18:30:47.324345808-05:00 [INFO] process unmapped keys: true
2024-04-22T18:30:47.324701032-05:00 [INFO] NOTE: kanata was compiled to never allow cmd
2024-04-22T18:30:47.33408874-05:00 [INFO] config parsed
2024-04-22T18:30:47.334164698-05:00 [ERROR] Failed to open the output uinput device. Make sure you've added the user executing kanata to the `uinput` group
2024-04-22T18:30:47.334684937-05:00 [ERROR] Permission denied (os error 13)
Press enter to exit
Hold down h for ẖ sounds just fine. I do not use Vim keys; I use stock Emacs, pretty much, and I have a preference for the Dvorak layout, which breaks hjkl.
Hey @Kolev I forgot I had plans tonight, so it took me longer to get back to you. I have uploaded an example configuration which turns right alt key (AltGr) into a layer hold. Right now it only affects the h key but you can map other keys as well if you like. I haven’t tested it (don’t have my laptop now, but where’s the fun if it’s fully done, but you shouldn’t have issues, let me know if you do).
You don’t need to keep a terminal running, you can run it as a system service, the instructions are in the last section of the same guide.
@Kolev looks like I go the unicode wrong. You can replace line 25’s 1e96 with the correct unicode sequence. But looks like the layer switch is working as you expect, just printing the wrong character, correct?