Repurposing "menu" button on Windows keyboards used in OS X

Windows keyboards map pretty intuitively to OS X, leaving only the "context menu" button a little purposeless. I would like the menu key to behave as another Command key.

How does one define what the "context menu" key on Windows keyboards does in OS X?

enter image description here

On this keyboard, the "context menu" key is directly under the "." (period/greater than) key; on the bottom row between "alt" and "ctrl" on the right side, two keys to the left of the "left arrow" key. What does it do in OS X, and what is it called?


Solution 1:

It has neither purpose nor name in OS X.

Maybe Karabiner could do it, if you can figure out what key code it sends - try Key Codes to see if it generates anything usable.

Solution 2:

Starting with macOS 10.12 Sierra this can be accomplished from the command line using the hidutil utility as described in Technical Note TN2450.

Using the table of key usage IDs at the bottom of the technical note you can find the IDs of the Application (i.e. context menu) key and the right GUI (i.e. command) key as 0x65 and 0xE7 respectively. Therefore the mapping can be done from the command line as follows:

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

The mapping won't survive reboots, but can be made persistent using a launchd agent by placing a property list such as the following in the appropriate launch agent directory (for instance ~/Library/LaunchAgents for your user):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.local.KeyRemapping</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/hidutil</string>
        <string>property</string>
        <string>--set</string>
        <string>{"UserKeyMapping":[
            {
                "HIDKeyboardModifierMappingSrc": 0x700000065,
                "HIDKeyboardModifierMappingDst": 0x7000000E7
            }
        ]}</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Solution 3:

To expand on @Tetsujin's answer: you can indeed achieve this with Karabiner. Here are some detailed instructions.

In short: go to the Misc & Unistall tab, open private xml, change it to:

<?xml version="1.0"?>
<root>
  <item>
    <name>Menu key to option right</name>
    <identifier>private.menu_key_to_OPTION_R</identifier>
    <autogen>__KeyToKey__ KeyCode::PC_APPLICATION, KeyCode::OPTION_R</autogen>
  </item>
</root>

Go back to the Change Key tab, click Reload XML, and tick the new mapping you just made at the top of the list.

Karabiner has its own keyboard EventViewer in the Misc tab, so you don't need KeyCode.