Keyboard connected directly (Bluetooth)
When using an external keyboard on my 16" 2019 MBP or 13" M1 MBP (both running macOS Monterey 12.3.1 build 21E258), connected directly with Bluetooth to either of those two computers, I'm able to remap certain key combinations using the hidutil
command.
In my particular case, I have a US Layout Apple Magic Keyboard (model A1314), while both my laptops use the UK keyboard layout. I needed to remap the §/± key to ~ key, so that I can keep using the combination CMD + ~ the same as I always had, to switch between a given application's windows. All three keyboards (the external as well as both built-in keyboards) have the §/± key to the left of 1 key.
In order to achieve that, I have a bash script that runs at login (this is triggered with a .plist
file loaded with launchctl
), which is essentially a wrapper around hidutil
:
#!/bin/bash
#
# Remaps the 'paragraph' key to tilde
#
function usage() {
echo "Usage: keyremap.sh <enable|disable>"
}
if [[ $# != 1 ]]; then
usage
exit 1
fi
action=$1
productid_external='{"ProductID":0x23a}'
productid_builtin='{"ProductID":0x340}'
# Set productid variable, as per example below, to remap only specific
# keyboard, or leave empty to remap all connected keyboards
# productid="-m \'${productid_builtin}\'"
productid=""
if [[ ${action} =~ ^(e|en|ena|ena.*)$ ]]; then
hidutil property ${productid} \
-s '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035}, {"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000064}]}'
elif [[ ${action} =~ ^(d|di|dis|disa.*)$ ]]; then
hidutil property -s '{"UserKeyMapping": ""}'
else
usage
exit 1
fi
The above works when I have the keyboard connected directly to either of the computer with Bluetooth, as well as when using the built-in keyboard directly on each of the computers.
Universal Control
I would now like to remap the same keys on the computer which is controlled via Universal Control. Say, my keyboard is connected to my 16" MBP via Bluetooth, and I'm working on my 13" MBP M1 via Universal Control.
Unfortunately, it seems that the hidutil
has no effect on the keyboard "shared" via Universal Control. Additionally when I was trying to "sniff" the key presses using applications like Keycastr, it didn't register any keystrokes at all for anything I typed while connected via Universal Control. At the same time, if I typed using the built-in keyboard on the 13" MBP M1, those keystrokes were registered and displayed.
Has anyone ran into this and do you by any chance have an idea how to remap keys while using Universal Control?
sw_vers
build and version of the machines in play?