Remap eject key to backslash [duplicate]

Solution 1:

Scripting Key Remapping

Keys can be remapped via the command-line tool hidutil. For example, use the hidutil command-line tool to remap the 'A' key to the 'B' key as shown in Listing 1. The map array consists of two key/value pairs that contain the source (HIDKeyboardModifierMappingSrc) and destination (HIDKeyboardModifierMappingDstKey) of the key remapping. The keys take a hexadecimal value that consists of 0x700000000 or’d with the desired keyboard usage value (see Table 1 for usage values).

Listing 1: Remapping keys in a script Use The value From the Table Given In the Link

$ hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000004,"HIDKeyboardModifierMappingDst":0x700000005},{"HIDKeyboardModifierMappingSrc":0x700000005,"HIDKeyboardModifierMappingDst":0x700000004}]}'
)

A null result indicates that there are no key remappings active.

Listing 2: Checking Key Remapping state

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

https://developer.apple.com/library/content/technotes/tn2450/_index.html