31

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?

4
  • 1
    It has neither purpose nor name in OS X. My Win keyboard actually has a second Windows key there, with that one next to it to the right. 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
    – Tetsujin
    Feb 21, 2015 at 15:57
  • 1
    We have a special word for information like this here at SE, sir, and that word, sir, is answer! Should you be so kind as to supply this information using the answer box, I shall certainly accept it as such! Feb 23, 2015 at 1:12
  • Glad it helped - one rather crisp & dry answer provided, below :)
    – Tetsujin
    Feb 23, 2015 at 6:39
  • Related: apple.stackexchange.com/a/280677/274411
    – Rubén
    Dec 5, 2021 at 18:51

8 Answers 8

19

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.

3
  • 3
    Key Codes reports code 110 for the "context menu" button, and in deed Karabiner traps and repurposes it like I wanted! Feb 23, 2015 at 6:41
  • 1
    Karabiner has EventViewer integrated and offers to copy its findings to clipboard. I found KeyCodes a little confusing as it displays much more than needed by Karabiner. (See my "own" answer below.) Aug 21, 2017 at 16:27
  • 4
    With Karabiner's EventViewer I found that the context menu key on my Microsoft keyboard registers as "application". In Karabiner I was then able to map "application" to "right_gui" and it behaves like a Command key. Apr 20, 2018 at 12:34
20

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>
6
  • This is the best answer. Karabiner does alot more, as well as make the keyboard unrecognizable by logitech software (in my case)
    – GreatWiz
    Oct 7, 2020 at 12:30
  • 1
    I did the following mapping "HIDKeyboardModifierMappingSrc": 0x700000065, "HIDKeyboardModifierMappingDst": 0x7000000E6 for logitech G915
    – GreatWiz
    Oct 7, 2020 at 12:33
  • 1
    I used "HIDKeyboardModifierMappingDst": 0x7000000E6 to map the menu/hamburger button on a Microsoft Sculpt Ergonomic Keyboard to the right Option key.
    – Steve K
    Oct 19, 2020 at 17:51
  • 1
    Awesome, really appreciate this, also used 0x7000000E6 instead for a right Option, worked a charm. Mar 1, 2021 at 12:05
  • Thank you for posting this! I was able to set my menu button to be a "fn" key using "HIDKeyboardModifierMappingDst": 0xFF00000003 Jan 20, 2022 at 17:31
13

Doing @Steph's answer but with Karabiner:

  1. Install Karabiner from here
  2. In "Simple Modifications" tab, select your keyboard (mine was this "Microsoft.." one)
  3. Press on "Add item" to make those 4 modifications in the screenshot below

configuration

This will map your keys to be as follows:

enter image description here

0
7

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.

3
  • Karabiner no longer has a EventViewer or private.xml link in the misc tab. Won't seem to remap the menu key either. It does trigger as 110 in KeyCodes though
    – phazei
    Nov 20, 2017 at 3:59
  • EventViewer was moved to the menu item. Also, the key registers as "application" in the EventViewer, so mapping that key did it. Still didn't see any xml option
    – phazei
    Nov 20, 2017 at 4:05
  • As of Karabiner version 11.5.0, you can use the Simple Modifications tab to add another command key on the right hand side of the keyboard. The keyboard to Karabiner key name translation is: windows key => left command & menu key => application (at least on my keyboard, ymmv).
    – maogenc
    Jan 31, 2018 at 17:58
2

I found that Seil works to change the "context menu" key to the 'Option' function (I presume it would work to change to 'Command' as well, although I have not tried it) in El Capitan.

In 'System Preferences... | Keyboard' I changed the 'Option' to 'Command' and 'Command' to 'Option', so that the keys are in the same order as on my MacBook Pro, to facilitate "muscle memory".

Then in 'Seil Preferences | Setting | Keys on non-Apple keyboard' I checked 'Enable Application Key (Menu Key)' and set the keycode to '54' (according to 'Seil' this is 'Right Command', but probably because of the switch in 'Keyboard' it functions as 'Option'.

So that gives me this:

Keyboard

2

Karabiner doesn't seem to support OS Sierra yet but Karabiner Elements does. Installing it takes a bit of work but once you've done that you can map "application" to e.g. "right_command" to make it work like you described.

1
  • FWIW application is in the submenu of Keys in pc keyboards
    – jakub.g
    Nov 3 at 11:31
1

Repurposing "menu" button on a notebook's Windows keyboard in MacOS 10.12+

There is a new version of Karabiner ("Karabiner Elements 12.1" to be used with MacOS 10.12+) that imho justifies adding a separate answer to this topic, though I posted s.th. similar here before.
[ As I did upgrade to MacOS 10.13 (High Sierra) I had to use ApplePS2SmartTouchPad.kext to be able to re-map the "menu" button, which is now seen as scan_previous_track. ]

With Karabiner Elements you have to edit its ~/.config/karabiner/karabiner.json file, somewhat differently** to the above code …

First find out "menu" button's name on your keyboard via Karabiner EventViewer:
just press it once. [Mine is: scan_previous_track, yours' probably different … ]

Here is some code analogue to parts of what I posted above, opening & closing "Information":

{"description": "Finder: 'menu' key to æ-I / æ-W by pressing or holding",
    "manipulators": [
        { "conditions": [{ "bundle_identifiers": ["^com.apple.finder"],
                                         "type": "frontmost_application_if" }
                        ],
                "from": { "consumer_key_code": "scan_previous_track" },
          "parameters": { "basic.to_if_alone_timeout_milliseconds": 200,
                          "basic.to_if_held_down_threshold_milliseconds": 500
                        },
         "to_if_alone": [{ "key_code": "i",
                           "modifiers": ["right_command"]
                        }],
     "to_if_held_down": [{ "key_code": "w",
                           "modifiers": ["right_command"],
                           "repeat": false
                        }],
        "type": "basic"
        }
                    ]
}

  (If pressed briefly Cmd-I is triggered, after holding the button for half a second: Cmd-W)

from, to… and type are mandatory expressions for re-mapping
conditions, parameters define exclusively affected app(s) and time thresholds for events**
"repeat": false keeps this code from unintentionally closing more than one window
– This code would be inserted between "rules": [ ]'s brackets (possibly with "," added)
    (I made shortcuts for my browser's history-back and -forward function with press & hold, too)
– Have a look into Karabiner Elements json Reference Manual

(** KE no longer supports conditional selection by uielementrole, but a few other conditions.)

0

I use MacOSX 10.11.6 El Capitan (from a broken Mac mini) on an hp-2570p EliteBook, so the Windows menu-key isn't recognized as "PC_APPLICATION" but simply as "FN" = function key.
Unfortunately this key blocks secondary keys so I had to do some more elaborate twitching to get where I wanted:

Using Karabiner (with integrated EventViewer for information on keys/names/windownames) I reused the key to:
– mimic æ-i in Finder (repeat for closing)
– mimix æ-i in VLC ( – " – )
– do history-back in Safari
Further I made other non-menu-key changes:
redefined some keys that aren't labeled correctly on my German keyboard
– made access to pageUp/Down "one-handed" on my keyboard (not shown)

I'll probably find some more simplifications in other applications over time ...
I used this "individual" code in "private.xml" (details: see post by antoine):

<!-- 1st item redefines <,>,^,° for my keyboard (effective for further items !!!)
<item>  
    <name>Switch_specialKeys_^_°</name>
    <identifier>private.Switch_specialKeys_^_°</identifier>
        <autogen>__KeyToKey__ KeyCode::BACKQUOTE, ModifierFlag::SHIFT_L, KeyCode::GERMAN_U_UMLAUT, ModifierFlag::SHIFT_L | ModifierFlag::OPTION_L</autogen>
        <autogen>__KeyToKey__ KeyCode::BACKQUOTE, KeyCode::6, ModifierFlag::SHIFT_L | ModifierFlag::OPTION_L</autogen>
        <autogen>__KeyToKey__ KeyCode::DANISH_DOLLAR, KeyCode::BACKQUOTE</autogen>
        <autogen>__KeyToKey__ KeyCode::BACKQUOTE, KeyCode::DANISH_DOLLAR, ModifierFlag::SHIFT_L</autogen>
</item>

<!-- Next 2 items differentiate "Cmd-i/-w" via (not-)AXWindow for dual use -->
<item>
    <name>WinR-FNDR æ-I</name>
    <identifier>private.WinMenu_to_Cmd-I</identifier>
    <uielementrole_not>AXWindow</uielementrole_not>
    <only>FINDER</only>
        <autogen>
          __KeyToKey__ KeyCode::FN, KeyCode::I, ModifierFlag::COMMAND_L
        </autogen>
</item>
<item>
    <name>WinR-FNDR æ-W</name>
    <identifier>private.WinMenu_to_Cmd-W</identifier>
    <only>FINDER</only>
    <uielementrole_only>AXWindow</uielementrole_only>
        <autogen>
          __KeyToKey__ KeyCode::FN, KeyCode::W, ModifierFlag::COMMAND_L
        </autogen>
</item>

<!-- For VLC the <uielementrole_only> elements are "AXWindow" for the main
     window and "AXRadioButton" for its information window. -->

<!-- My shortcut for Safari's "history-back" consists of this definition:
     <autogen>
        __KeyToKey__ KeyCode::FN, KeyCode::CURSOR_LEFT, ModifierFlag::COMMAND_L
    </autogen>      -->

For PC applications running under CrossOver the application names aren't recognized by Karabiner, so I used <appdef> to (re)define their names and <windownamedef> to address a particular window; these definitions were then available in <only> and <windowname_only> tags.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .