Friday Yak Shaving: I've been tinkering on and off with an
annoying problem: a MacBook Pro, with a Dell USB Keyboard plugged
into it, using Microsoft Remote Desktop to connect to XRDP to
control an AL2012 system running Gnome. The problem is that at the
end of that chain of technology, the Dell keyboard mappings for
the Option and Command keys (or Alt and Windows, if you prefer)
are incorrect. I'd used the macOS System Preferences to swap the
keys around - so the keys next to the spacebar on the Dell
keyboard match the Mac layout - but for some reason they didn't
work as expected in Gnome; the left and right Command keys
appeared to be swapped. What's inolved here is a long chain:
firstly, the non-native keyboard requires some form of mapping,
then the XRDP client does some mapping, and then the Gnome session
does some mapping, and at the end of that if anything actually
works it's sort of a miracle. And I'd no idea what part was
broken.
Eventually I realised that the swapped keys only happened on the
Dell keyboard, meaning that the likely sources of error were on
the Mac rather than the XRDP or Gnome ends of things. Some more
tinkering and a bit of Google searching and I found not one, but
two problems: firstly, I'd selected the wrong keyboard type from
the ISO/ANSI selector that came up when the keyboard was first
detected, and you only get that selector the first time around -
attempts to re-detect the keyboard type actually failed. Fixing
that was a matter of editing the file which records the keyboard
type, but that still left me with swapped keys. Further Google
searching lead me to an Apple technote about using
hidutil to modify keyboard layouts; my first attempt at
doing anything with this affected both the Dell and the built-in
keyboards, so that wasn't going to be a flyer. Further Googling
turned up a StackExchange discussion on using defaults
write to modify the global preferences file, but that didn't
take effect (the file was modified, but the keymappings didn't
take) and fiddling with the System Preferences resulted in the OS
cleverly swapping the left and right Command keys
again. Eventually I put both pieces together and figured out how
to have hidutil target only the Dell keyboard, at which
point everything magically worked. What I haven't yet checked is
to see if this persists across unplugging and replugging the
keyboard, but at least I know how to fix it. And so, presenting
the fruits of my labours:
hidutil property -m '{"ProductID":0x2003,"VendorID":0x413c}' \
-s '{"UserKeyMapping":[ \
{"HIDKeyboardModifierMappingSrc":0x7000000e2,\
"HIDKeyboardModifierMappingDst":0x7000000e3},\
{"HIDKeyboardModifierMappingSrc":0x7000000e3,\
"HIDKeyboardModifierMappingDst":0x7000000e2},\
{"HIDKeyboardModifierMappingSrc":0x7000000e6,\
"HIDKeyboardModifierMappingDst":0x7000000e7},\
{"HIDKeyboardModifierMappingSrc":0x7000000e7,\
"HIDKeyboardModifierMappingDst":0x7000000e6}]}'
Easy, huh? I still have to sort out the mapping on the Gnome end
of things, mind you, because it's pretty convinced that I'm using
a US keyboard layout, and it denies the existence of some of the
alternatives that clearly exist in the keyboard
configs.