The possible usage scenario is

  1. Determine an unused key on the keyboard

  2. Check the documentation at Technical Note TN2450: Remapping Keys in macOS 10.12 Sierra

  3. Determine the trigger key. E.g. caps lock. Check its hex code. Or Use skhd to get hex code of any key on the keyboard using the following command:

   skhd -o
OR

Free hidutil file generator

  1. Prepare a .json document:
{
	"UserKeyMapping": 
	[
		{	
			"HIDKeyboardModifierMappingSrc": 0x700000039,
			"HIDKeyboardModifierMappingDst": 0x700000073
		}
	]
}
  1. Run
   hidutil property --set "$(cat ~/capslock_to_f19.json)"
  1. Check if it is working properly;
   hidutil property --get "UserKeyMapping"

The caps lock key must not work any more. Debug it through skhd -o command.

Disabling Key Mapping

By default when you restart the system, keymappings are deleted by default. If you don’t want to restart the system, you can use the following command:
hidutil property --set '{"UserKeyMapping":[]}'