Like a USB keyboard, YubiKeys work via inputting scan codes as opposed to actual characters. This means that when you type, the keyboard only sends the key number, or “scan code”, which the computer then translates depending on your keyboard settings.
This presents an issue as there are many different keyboard layouts in use in the world today. In order to mitigate the problem, the YubiKey only uses modhex (modified hexadecimal for short) characters, which are characters which are mapped to by the same scan codes in almost all keyboard layouts. If your chosen keyboard layout is not one of those covered by the modhex system (like Dvorak, etc), your YubiKey might not be able to output the characters correctly. If this is true for you, here are 3 ways to resolve the issue.
Our recommended “best practice” is to switch to a US standard keyboard layout when entering the OTP and switching back when done. When properly configured this is quick and convenient – in a Windows environment, for example, pressing Windows Key + Space will allow one to quickly switch to an alternative keyboard layout. On Macs running Monterey (macOS 12) or newer, the fn or Globe key can be configured to switch layouts (or Change Input Source) via System Preferences > Keyboard.
If you are trying to output digits (0-9) with the French AZERTY keyboard layout, you can hold the Shift key on your keyboard while using the YubiKey, or enable the flag shown below in the YubiKey Personalization Tool. After checking the box next to Use numeric keypad for digits (2.3+), click Update Settings..., select one of the configuration slots, and click Update.
If neither of the previous options are possible for you, another solution would be to modify the scanmap used by your YubiKey. This feature requires the command line version of the cross-platform YubiKey Personalization Tool and, after performing the operation, your YubiKey will only work properly on the keyboard layout that you have modified it for. For instance, if you modified it for a Dvorak keyboard layout, it can only be used on the Dvorak keyboard layout.
The YubiKey uses the following alphabet:
The scanmap is the 1 byte scan code for each of those characters. So for a US standard keyboard layout (and the YubiKey default), the scanmap is:
To set the scanmap, use the -S argument of the ykpersonalize tool and then affix the desired scanmap after. Shown below are some example scanmaps.
Simplified US Dvorak:
Turkish QWERTY (with a dotless i instead of a standard i):
Note that you must remove any whitespace present in these examples before using the values. Leaving the argument empty will reset the scanmap to the YubiKey’s default.
The screenshot above shows a YubiKey 5 Series scanmap being configured for the Dvorak keyboard layout.