Keyboard layouts in lightweight virtualisation

I recently looked in detail at the features and shortfalls in lightweight macOS virtual machines running on Apple silicon hosts. One subject that I didn’t explore in depth there was that of keyboard layout.

There are two main physical keyboard formats in use with Macs: those based on the US ANSI standard, and those following international ISO standards. These differ in several respects, for example the left and right Shift keys are the same width in ANSI, but in ISO the left Shift key is narrower to accommodate an additional key between it and the first alphabetic key on the bottom row. For the purposes of this article, the critical difference is that the ISO keyboard has an extra key compared with the ANSI.

Apple has long shipped Macs and keyboards supporting both physical formats according to markets. In Europe, that means ISO as a rule, even in the UK where the British English keyboard layout is otherwise similar to that of the US. macOS is clever about handling these different physical keyboards: open the Keyboard Viewer and the layout there is automatically matched with the keyboard connected to that Mac. At least, it is unless it’s in a lightweight macOS VM.

Even when virtualising a Sonoma guest on a Sonoma host, with the latest keyboard support using VZMacKeyboardConfiguration, the keyboard in every macOS or Linux VM is ANSI in format, whether or not the physical keyboard of that Mac is ANSI or ISO. Neither is there any option offered for macOS or Linux guests to use an ISO keyboard format.

For British English users, this isn’t a significant problem, as the key missing from the ANSI format is used for the obscure and little-used characters § and ±, and doesn’t have Option-based combinations. For other European languages the loss is far more significant, as the following layouts demonstrate. These are taken from the host, a MacBook Pro M1 Pro with ISO format keyboard, and a Viable guest VM using VZMacKeyboardConfiguration with the selected keyboard layout.

isobr

Above is the standard ISO British layout on the host, and below is the same from the VM in ANSI layout. After the rearrangement of keys, the missing key from the VM is that shown at the left of the numeric row, for the § and ± characters. Pressing the extra key on an ISO keyboard shows it to be dead in the VM, in that no character appears as a result.

isobrvm

isodk

When both keyboards are laid out for standard Danish, above for ISO (host) and below for ANSI (VM), the missing key is more significant, as it contains the $ and § keys. Although the $ character is still available using a different (and obscure) key combination, this a problem for anyone using the Danish layout.

isodkvm

isofr

This becomes even more critical when using the standard French layout in a VM. Now the key missing from the ANSI (VM) layout below is that used for @ and #, both of which are commonly used in computing. Again, they are available elsewhere in the ANSI layout, but this is a serious stumbling block for anyone using the French layout in a VM.

isofrvm

The net effect of the current lack of support for ISO layouts in lightweight virtualisation is that using a macOS or Linux VM with anything other than an English layout is awkward at best, and for some languages it’s almost unusable, with no workaround available. As this is built into the API, this affects all implementations that use macOS lightweight virtualisation, including Parallels, UTM, VirtualBuddy, and my own Viable.

Unfortunately, I suspect the only way to remedy this is to build ISO format support into the VirtIO keyboard driver. Although that may seem a lot of work for the addition of a single key, as I’ve shown above, for some languages that’s quite a show-stopper for many users. I hope that Apple’s engineers can find the time to address this and make lightweight virtualisation international.

I have now reported this as Feedback to Apple, reference FB12460075.

I’m very grateful to ‘A passerby…’ for drawing my attention to this, and having the patience for me to see what should have been obvious all along.