If you’re using a non-QWERTY keyboard layout like Dvorak, Colemak, or Bépo, you may find that YubiKey OTPs outputs incorrect characters.
This works rather well, in general. For example, when I ask for a new OTP, the yubikey sends the following code:
tgghcilbddhuuejckujlglctvlckjeuudlfugtrderne
Behind the scenes, keycodes are sent instead of characters. For example, for this OTP, the following keycodes would be sent:
89
73
73
…
The OS1 then translates the keycode to a character.
In general, this works mostly everywhere, because almost all countries have a keyboard layout that share the same common keys at the same place.
However, when someone has an alternative, ~better,~ layout like Dvorak, Colemak, or Bépo, the OTP no longer works and outputs something like:
iyedidjcnxh.dcbpjtubbnhdty.hhujnx.jpycuyjjuc
if you are using Dvorak, or:
,èic,cxdrktp.croxèsvxc'e.ksepièd'esèkèe.xv.o
for those of you using Bépo.
One solution is to constantly switch layouts before entering an OTP, but this is a real PITA when the OTP must be entered many times per day.
In sway, fortunately, it is possible to define a specific keyboard layout per device.
Do do that, you must first find the identifier of your yubikey:
$ swaymsg -t get_inputs
----8<----
Input device: Yubico YubiKey OTP+FIDO+CCID
Type: Keyboard
Identifier: 4176:1031:Yubico_YubiKey_OTP+FIDO+CCID
Product ID: 1031
Vendor ID: 4176
Active Keyboard Layout: English (Dvorak)
Libinput Send Events: enabled
----8<----
as you can see, in my case, before changing the configuration, the (default) layout of the device is Dvorak.
You can then change the layout of the yubi in your sway config:
input '4176:1031:Yubico_YubiKey_OTP+FIDO+CCID' {
xkb_layout "us"
xkb_variant ""
}
🎉 No more layout changes!
As of 2025, however, unless I’m mistaken, this is not possible to do on GNOME or KDE yet.
Well, in Wayland, it’s the Compositor’s role to do that. Sway, for example, uses xkb for converting the keycode to a keysym, and then a char. ↩︎