Kanata: Cross-platform multi-layer keyboard remapper with advanced customization
github.com
github.com
The elevator pitch I give for this software is "QMK for any keyboard" - you can use layers, tap dance etc. with regular keyboards that have programming symbols in sane locations with dedicated keys.
I use this with a Logitech Ergo K860, and have taken it a step further to integrate with my window manager so that layers change automatically based on the focused application[1].
Thanks to it, I'm using a Miryoku with Colemak-dh layout over a Razer Mechanical keyboard. I even removed the extra keys from it, which makes the keyboard a sight to see.¹
But Kanata is the real star in this show, making all the magic happen.
It's so flexible and configurable that through its blessings I've finally gone completely mouseless. I just keep my hands steady on the keyboard and my thoughts get converted to whatever action I need on screen. The humanities writer dream!
I have great respect for jtroo for creating this software. It's a perfect example of how well designed software allows to go beyond the seeming physical constraints imposed by hardware.
1. That's also why I need it so badly on a new install...
O.o
How do you even go about learning a keymap like this?
That being said, this appears to be an active mapper that needs to be running in the background. Classic "with great power comes great responsibility". I'd rather have something less powerful that only offers the customizations that can be loaded into the native keyboard mapping engines. On Windows, I am extremely happy with a few tweaks I've built with Microsoft Keyboard Layout Creator (MSKLC). Mostly removing some of the worst pain points of my home language layout (German) that drive many of my compatriots to using an English layout (basically what nodeadkeys does on Linux, but with a few improvements like opting in to dead keys behavior with altgr+’). Would be super awesome to have a UI for setting up that kind of mapping that can output configurations for the native mapping mechanism across a range of platforms. And that only offers mappings that can be configured using the native system on all platforms supported, the intersection of capabilities.
For Linux, unfortunately xkb is overcomplicated and undercapable, and it's like pulling teeth to get a layout recognized as a first-class citizen by a Linux ‘desktop’.
(but I can't find any mention of the AltGr modified that most languages other than English use as their central exotica pivot? That's a surprising omission)
Keymapper was posted here ~10 days ago https://news.ycombinator.com/item?id=42871040, but the link received relatively little attention, so I assume it might have been missed by many.
Disclaimer: I'm active on the issue threads and a big fan. :)
it recently got a new chording feature where you can press a whole bunch of keys at once (or just two if you'd like) and something will happen. like, you could press the letters q and n at the same time and program Kanata to send the word question or some macro like a hotkey or a series of hotkeys and strings. it's all up to you. i have a QMK board, but because Kanata has many more features and isn't limited to the memory of its chip, i use Kanata instead of QMK to architect my layout, complete with multiple layers and many QoL niceties
My work laptop from Dell has an idiotic "copilot" key which sends something like ctrl+shift+f23 - three separate key presses on the scancode level.
I use dkey to map this otherwise useless crap chord to Ctrl.
With multi-profile keyboard mapping, I even have a gaming profile so I don't have to remap keys in the game(s).
Do the same with mice. Cross OS, my mouse can lower, raise, and mute the volume. Great in games too with improving the would audio to either listen for those to sneak up on or quickly lowering the extreme loud noise.
Only grip is that laptop keyboards need to move to the same custom firmware / configuration mapping like external for better cross OS support / user experience.
- turning my CapsLock into escape. As a vim user I use it all the time
- when CapsLock is held it turns into a hyper key. Hyper+e to switch to Emacs window, hyper+b to browser and so on
- creating application independent maps that work on Linux and MacOS: ctrl+w is always "kill last word", super+w to kill a tab or a window
- invoking hammerspoon commands on MacOS that tile windows, bring up window switcher, etc.
I tried some tiling WMs on MacOS(Amethyst?), but they never truly felt like tiling WMs on Linux. I could never reliably switch focus where I wanted it to go. This is not to disparage those projects; my config works well enough and I may not had given them a proper chance.
My tiling is manual and closer to Windows snap feature mixed with Power Toys zones.
It's not as good as a dedicated tiling wm on Linux - but it's less terrible than MacOs' mouse/touchpad chauvinism.
[1]: https://github.com/kbd/setup/blob/main/HOME/.hammerspoon/ini...
If you want to type french with a standard US keyboard for instance, it will require at least some small layering. Typing a CJK language will require some more tweaks, in particular the dual action on keys saves a lot. If you intend to type both accented and CJK with let's say the UK international layout, you'll need every help you can get.
When using vim more heavily, having an escape key remap as the control key's single action is also a huge QOL.
Once you're in it, it opens the door for a lot of small improvements.
i also have home, end, backspace, delete, pgup, pgdn, all close enough to the homerow on that layer as well so i dont have to reach out to the corners of the keyboard
then finally on the edsf keys i have it send whether the vscode shortcuts are to move the line up or down or indent/unindent.
most of the rest of the things i have remapped are just single key things that can be done in most other remappers, sending esc when the alt key is tapped, capslock to ctrl etc
- keydown space
- keydown a
- keyup a
- keyup space
I normally get the output <space><a>, interpreted in order of keydown, but kanata outputs in order of keyup, so I get <a><space>.i dont know if this would make a difference but i have "process-unmapped-keys yes" in my defcfg section
I like to use a US Intl keyboard layout for programming but as I am German I need äöüß a lot - so I've used a custom keymap for caps-aous for years (and a couple other things). Yes, you can get most OSes to somehow do this, but just doing it at firmware level would fix SO MANY PROBLEMS.
There are some keyboards, however, which send multimedia commands via USB “out of band” from normal key codes, and which therefore cannot be remapped that way.
[0] https://github.com/jtroo/kanata/blob/main/parser/src/keys/mo...
[1] https://jtroo.github.io/config.html#key-names
In case you are on Windows, I would recommend SharpKeys [2] for basic remappings.
I use a mix of setxkbmap to remap the control key and AutoKey but each has its issues. Can this replace those?
It should be able to do whatever you suggest. But it can be a lot of configuration. I use 3 different layouts in 2 languages and that will be too much to configure manually. Instead, I just use 2 layers that are mostly just pass-through (they just pass the keystrokes to the native xkb layout). Layer1 is entirely pass-through except for a single tap-dance key to switch to layer 2. Layer2 has some additional features like home-row-mods that are not possible with plain xkb. The keyboard layouts are managed by xkb. Thus I'm able to use the features of both xkb and kanata.
It is likely that AHK has some features not in Kanata, so you would have to explain what you do.
Also recently, I've remapped my siblings laptop meta and rctrl key to lalt and meta respectively because the original alt key got damaged. Thanks jtroo for creating this you rocks!
I live in a town called Kanata west of Ottawa, Canada. I never know the meaning of the name. Thanks for explanation of "Kanata"
Does Kanata support chords like jk to escape with a configurable timeout on when k is pressed, say 80ms or so?
On macos limitations, kernel extensions are officially deprecated so I don't think we'll see a mechanism that can hook deep enough into the keyboard manager system to allow for complex chords. That's what Karabiner did as kernel ext. before switching to Elements, and the timeout workaround was introduced at that time if I remember correctly.
Added later: This is what I get on my sway desktop in addition to the physical keyboard:
Input device: kanata
Type: Keyboard
Identifier: 1:1:kanata
Product ID: 1
Vendor ID: 1
Active Keyboard Layout: English (US)
Libinput Send Events: enabled
And the mapping from the physical keyboard to the virtual keyboard is done by kanata running as a user service (without root privileges). You just need to give uinput access privilege to your user account.