How I got a Yubikey working with a Dvorak keyboard and Karabiner-Elements
I needed to set up a new Yubikey device, which plugs into my Mac laptop via USB-C and injects one-time codes by pretending to be a keyboard.
Problem: I use Dvorak... so the Yubikey codes were coming through incorrectly and failing to work.
https://superuser.do/2014/10/22/yubikey-support-for-non-qwerty-keyboard-layouts-on-mac-os-x/ has a recipe for fixing this using Karabiner. But... those instructions are for an older Karabiner which is configured using XML files.
The latest Karabiner - Karabiner-Elements - uses a JSON configuration instead.
Here's how I got it working:
Installed Karabiner Elements 12.1.0 from https://pqrs.org/osx/karabiner/
Launched Karabiner Elements for the first time (to ensure it would create its config files). Enabled it for the Yubikey in devices:
- Added a single key mapping specific to the Yubijey, in order to see how that looks in the config:
Opened up the freshly generated
~/.config/karabiner/karabiner.jsonfile to see what it looks like.
Rebuilt the JSON section for the
"simple_modifications"for that keyboard, starting with the XML example here: https://gist.github.com/sudowork/c7f182752a929d08a5ac - the hardest part was figuring out the keywords for non-alphanumeric-characters - I ended up consulting the Karabiner source code for those: https://github.com/tekezo/Karabiner-Elements/blob/d9cdf3312d3aa2f9887fd270a59e30f9670fc39c/src/share/types.hpp#L231-L448
The JSON is attached to this gist.
- Saved the new JSON in
~/.config/karabiner/karabiner.json. Useful tip: just hitting "save" on that file causes Karabiner to refresh its configuration - and the "Log" tab in the UI is really helpful here as it will directly display any validation errors in the JSON.
I tested the Yubikey in a text file, by running it in Dvorak and QWERTY mode and with and without the Karabiner modifications enabled. This gave me confidence that it was doing the right thing.
And... it worked! I can now use my Yubikey to sign in even though my regular keyboard layout is Dvorak.