macOS: Remap a key

You can use hidutil to remap keys in macOS without using a third party application.

List current mappings, will return (null) if no mappings are present:

$ hidutil property --get "UserKeyMapping"
(null)

Set a mapping, in this case, make Right Shift (0xE5) work as Enter (0x28) instead:

$ hidutil property --set '{"UserKeyMapping":
  [{"HIDKeyboardModifierMappingSrc":0x7000000e5, "HIDKeyboardModifierMappingDst":0x700000028}]
}'

To set multiple mappings, add corresponding objects to the array.

See this table for a full list of keys and their IDs. Some common ones include:

Name Id
Enter 0x28
Escape 0x29
Backspace 0x2A
Tab 0x2B
Space 0x2C
Caps Lock 0x39
Left Control 0xE0
Left Shift 0xE1
Left Option 0xE2
Left Cmd 0xE3
Right Control 0xE4
Right Shift 0xE5
Right Option 0xE6
Right Cmd 0xE7