MacOS – Unmap key combinations in KeyRemap4Macbook

keyboardmacosremote desktop

This is a follow up to How can I map the Windows key to option in Microsoft Remote Desktop version 8?. The answers to that question are a huge timesavers for OSX RDC users; however, there are some key combinations I don't want remapped. For example, Command+Q and Command+W would ideally still function the same as they do before remapping.

I tried adding this definition:

<autogen>
    __KeyToKey__ 
    KeyCode::Q, ModifierFlag::COMMAND_L, 
    KeyCode::Q, ModifierFlag::COMMAND_L
</autogen>

But to no effect.

Update: here is the full private.xml:

<root>
    <appdef>
        <appname>Microsoft Remote Desktop</appname>
        <equal>com.microsoft.rdc.mac</equal> 
    </appdef>
    <item>
        <name>Swap command and option in Remote Desktop</name>
        <identifier>private.remotedesktopswapcommandandcontrol</identifier>
        <only>Microsoft Remote Desktop</only>
        <autogen>
            __KeyToKey__ 
            KeyCode::Q, ModifierFlag::COMMAND_L, 
            KeyCode::Q, ModifierFlag::COMMAND_L
        </autogen>
        <autogen>__KeyToKey__ KeyCode::TAB, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_OPTION, KeyCode::TAB, ModifierFlag::COMMAND_L</autogen>
        <autogen>__KeyToKey__ KeyCode::OPTION_L, KeyCode::COMMAND_L</autogen>
        <autogen>__KeyToKey__ KeyCode::COMMAND_L, KeyCode::OPTION_L</autogen>
        <autogen>__KeyToKey__ KeyCode::OPTION_R, KeyCode::COMMAND_R</autogen>
        <autogen>__KeyToKey__ KeyCode::COMMAND_R, KeyCode::OPTION_R</autogen>
    </item>
</root>

Best Answer

The documentation suggests that these shouldn't conflict:

<autogen>
   __KeyToKey__
   KeyCode::Q, ModifierFlag::COMMAND_L | ModifierFlag::NONE,
   KeyCode::Q, ModifierFlag::COMMAND_L | ModifierFlag::NONE,
</autogen>
<autogen>__KeyToKey__ KeyCode::COMMAND_L, KeyCode::OPTION_L</autogen>

However, the second <autogen> will override the COMMAND_L of the first. The solution is counterintuitive:

<root>
    <appdef>
        <appname>Microsoft Remote Desktop</appname>
        <equal>com.microsoft.rdc.mac</equal> 
    </appdef>
    <item>
        <name>Swap command and option in Remote Desktop</name>
        <identifier>private.remotedesktopswapcommandandcontrol</identifier>
        <only>Microsoft Remote Desktop</only>            
        <autogen>__KeyToKey__ KeyCode::TAB, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_OPTION, KeyCode::TAB, ModifierFlag::COMMAND_L</autogen>
        <autogen>__KeyToKey__ KeyCode::OPTION_L, KeyCode::COMMAND_L</autogen>
        <autogen>__KeyToKey__ KeyCode::COMMAND_L, KeyCode::OPTION_L</autogen>
        <autogen>__KeyToKey__ KeyCode::OPTION_R, KeyCode::COMMAND_R</autogen>
        <autogen>__KeyToKey__ KeyCode::COMMAND_R, KeyCode::OPTION_R</autogen>
        <autogen>
            __KeyToKey__
            KeyCode::Q, VK_OPTION | ModifierFlag::NONE,
            KeyCode::Q, VK_COMMAND | ModifierFlag::NONE,
        </autogen>
    </item>
</root>

In this case Cmd+Q is remapped to Opt+Q but then Opt+Q is remapped back to `Cmd+Q'.