Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign a key remapping to specific device using hidutil

Tags:

macos

As seen in this article from Apple, you can remap a key from the command line in OS Sierra with something like:

hidutil property --set '{"UserKeyMapping": 
  [{"HIDKeyboardModifierMappingSrc":0x700000054,
    "HIDKeyboardModifierMappingDst":0x700000067
  }]
}'

Is it possible to assign this change only to a specific keyboard device, e.g. if you want to map one device to the output of a second, but not affect the function of the second?

The article is no longer updated and there appears to be no current documentation of how the command works.

like image 280
NFB Avatar asked Feb 04 '23 20:02

NFB


1 Answers

I'm not quite sure what you mean by "if you want to map one device to the output of a second, but not affect the function of the second?", but the rest of your question sounds like you just want to remap a specific external device. This can be accomplished with the following command:

hidutil property --matching '{"ProductID":0x123}' --set '{"UserKeyMapping": 
 [{"HIDKeyboardModifierMappingSrc":0x700000054,
   "HIDKeyboardModifierMappingDst":0x700000067
 }]
}'

You'll need to determine your specific ProductID and insert it into the command above. You can find ProductIDs for internal and external devices at the following location:

Apple icon > About This Mac > System Report > USB (under Hardware section in left panel)

These changes will be reverted after each restart. In order to make this fix permanent, follow the solution provided in this answer.

like image 117
DarthRitis Avatar answered Feb 08 '23 16:02

DarthRitis