MacOS – How to disable a key completely

keyboardmacos

I want to learn emac keybindings, but I have a bad habit of using arrow keys. Is there a way to disable the arrow keys temporarily (through software)?

Best Answer

You can disable them in most text views by saving a property list like this as ~/Library/KeyBindings/DefaultKeyBinding.dict:

{
    "\UF700" = noop:;
    "\UF701" = noop:;
    "\UF702" = noop:;
    "\UF703" = noop:;
    "$\UF700" = noop:;
    "$\UF701" = noop:;
    "$\UF702" = noop:;
    "$\UF703" = noop:;
    "~\UF700" = noop:;
    "~\UF701" = noop:;
    "~\UF702" = noop:;
    "~\UF703" = noop:;
    "~$\UF700" = noop:;
    "~$\UF701" = noop:;
    "~$\UF702" = noop:;
    "~$\UF703" = noop:;
    "@\UF700" = noop:;
    "@\UF701" = noop:;
    "@\UF702" = noop:;
    "@\UF703" = noop:;
    "@$\UF700" = noop:;
    "@$\UF701" = noop:;
    "@$\UF702" = noop:;
    "@$\UF703" = noop:;
}

If you use bash, you can disable arrow keys (without other modifier keys) by adding this to ~/.inputrc:

"\e[A":
"\e[B":
"\e[C":
"\e[D":

If you want to disable them completely, you can add this to KeyRemap4MacBook's private.xml:

<autogen>__KeyToKey__ KeyCode::CURSOR_LEFT, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_RIGHT, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_UP, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_DOWN, KeyCode::VK_NONE</autogen>

This would only disable them in TextMate, TextEdit, Terminal, and iTerm, and only affect some key combinations:

<only>TEXTMATE, EDITOR, TERMINAL</only>
<autogen>__KeyToKey__ KeyCode::CURSOR_LEFT, ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_RIGHT, ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_UP, ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_DOWN, ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_LEFT, VK_SHIFT | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_RIGHT, VK_SHIFT | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_UP, VK_SHIFT | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_DOWN, VK_SHIFT | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_LEFT, VK_OPTION | VK_SHIFT | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_RIGHT, VK_OPTION | VK_SHIFT | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_UP, VK_OPTION | VK_SHIFT | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_DOWN, VK_OPTION | VK_SHIFT | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_LEFT, VK_OPTION | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_RIGHT, VK_OPTION | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_UP, VK_OPTION | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_DOWN, VK_OPTION | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>