15

This shortcut drives me crazy. I would like to remap command-tab for snippet insertion while coding, but the switcher gets in the way...

4 Answers4

8

You can map command-tab to another key combination with Karabiner Elements:

<autogen>__KeyToKey__ KeyCode::TAB, VK_COMMAND | ModifierFlag::NONE, KeyCode::F19</autogen>

This would disable command-tab and shift-command-tab:

<autogen>__KeyToKey__ KeyCode::TAB, VK_COMMAND | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::TAB, VK_COMMAND | VK_SHIFT | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
John D
  • 105
Lri
  • 42,502
  • 8
  • 126
  • 159
1

Adding to John's answer using Karabiner Elements. When installing it as of May 22, 2022 I can't seem to find a way to add xml configurations. Everything is in json! So here's how I did it:

In preferences, click the "Open config folder" button.

enter image description here

You'll be taken to a folder that has a karabiner.json file. Open that file to edit it.

Within the file you'll see a simple_modifications field. This is what I added to it to disable CMD+Tab:

            "simple_modifications": [
                {
                    "from": {
                        "key_code": "left_command"
                    },
                    "to": [
                        {
                            "key_code": "left_option"
                        }
                    ]
                },
                {
                    "from": {
                        "key_code": "left_option"
                    },
                    "to": [
                        {
                            "key_code": "left_command"
                        }
                    ]
                },
                {
                    "from": {
                        "key_code": "tab",
                        "modifiers": {
                            "mandatory": [
                                "command"
                            ]
                        }
                    },
                    "to": [
                        {
                            "key_code": "f13"
                        }
                    ]
                }
            ],

In my case you can see that I've swapped left option and left command first. And then I disable CMD + Tab. It seems key_code f13 is the option to do nothing.

Hope this helps!

b.lyte
  • 111
1

You can do it as the assembly level. For ML 10.8.3, this Cmd+Tab registration happens in subroutine at address 0x10000b258. In pseudo-code, it looks like:

rax = CPSRegisterForKeyOnConnection(*(int32_t *)rbx, 0x1002cd078, 0x1, 0x1);
if (rax != 0x0) {
    fprintf(**__stderrp, "Error registering cmd-tab key, %d\\n");
}
rax = CPSRegisterForKeyOnConnection(*(int32_t *)0x1002ccda8, 0x1002cd078, 0x2, 0x1);
if (rax != 0x0) {
    fprintf(**__stderrp, "Error registering cmd-shift-tab key, %d\\n");
}

So if you replace the following byte codes:

488D35691C2C008B3BBA01000000B901000000E85CD71B0085C0741A488B0DD5FC2400488B39488D355B341C0089C230C0E892C51B00488D0563192C008B38488D352A1C2C00BA02000000B901000000E81FD71B0085C0741A488B0D98FC2400488B39488D3541341C0089C230C0E855C51B00

with:

90909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090

And resign your Dock.app, it will work. You also have to unprotect the Dock binary before you do this as the Dock binary is encrypted.

Canadian Luke
  • 24,640
0

Would an acceptable answer include remaping it?

Mac OS X Lion (10.7) has difficulty detecting the keyboard layout when I first plugged it in. But after following the instructions (i.e. press the key to the right of Left Shift, etc.) it correctly identifies the layout.

In System Preferences, Lion has a wonderful keyboard panel:

Screen shot of Lion's keyboard panel

Next, go to Modifier Keys…

enter image description here

Bingo, now CapsLock behaves as Control.

Or, you could try and effect the key bindings:

Edit the default keybindings file, ~/Library/KeyBindings/DefaultKeyBinding.dict. Create the directory and/or the file if they’re not already there, and make it look like this:

{
  /* Remap Home / End to be correct */
  "\UF729" = "moveToBeginningOfLine:"; /* Home */
  "\UF72B" = "moveToEndOfLine:"; /* End */
  "$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
  "$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
}

If there are already entries in DefaultKeyBinding.dict, just add the 4 new mappings above to the main section of your file. A reboot may be needed to get it to take effect.

You will need to adjust the code above for what you are trying to do

Everett
  • 6,113
  • 1
  • 24
  • 34