How can I rebind keyboard keys in OS X?
Solution 1:
To enable CmdÖ -> \ just remap the key combo with Karabiner. The shortcut you need isn't pre-defined so you have to write your own:
- Download, install and open Karabiner
- Open in the menulet Karabiner -> Preferences
- Open the tab Misc & Uninstall
- Hit the button Open private.xml
- Open the file private.xml with an appropriate editor
-
Enter the customized keycode
Example 1 (cmdÖ -> \):
<?xml version="1.0"?> <root> <item> <name>Command-Ö to Backslash</name> <appendix>(Change Command-Ö to \)</appendix> <identifier>remap.command_ö_to_backslash</identifier> <autogen>__KeyToKey__ KeyCode::GERMAN_O_UMLAUT, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND, KeyCode::KEY_7, ModifierFlag::SHIFT_L | ModifierFlag::OPTION_L</autogen> </item> </root>
Example 2 (cmd_RÖ -> \ cmd_R is the right command key only, cmd_LÖ doesn't have an output!):
<?xml version="1.0"?> <root> <item> <name>Command_R-Ö to Backslash</name> <appendix>(Change Command_R-Ö to \)</appendix> <identifier>remap.command_r_ö_to_backslash</identifier> <autogen>__KeyToKey__ KeyCode::GERMAN_O_UMLAUT, ModifierFlag::COMMAND_R, KeyCode::KEY_7, ModifierFlag::SHIFT_L | ModifierFlag::OPTION_L</autogen> </item> </root>
Example 3 (cmd_R -> \ you can't use the right command key for any other purpose then):
<?xml version="1.0"?> <root> <item> <name>Command_R to Backslash</name> <appendix>(Change Command_R to \)</appendix> <identifier>remap.command_r_to_backslash</identifier> <autogen>__KeyToKey__ KeyCode::COMMAND_R, KeyCode::KEY_7, ModifierFlag::SHIFT_L | ModifierFlag::OPTION_L</autogen> </item> </root>
Example 4 (cmd_R -> \ similar to example 3 but you can use the right command key as normal command key-> hitting cmd_R yields \ but cmd_RS saves files):
<?xml version="1.0"?> <root> <item> <name>When you type Command_R only, send Backslash</name> <appendix>(Change Command_R lazy to \)</appendix> <identifier>remap.command_r_lazy_to_backslash</identifier> <autogen>__KeyOverlaidModifier__ KeyCode::COMMAND_R, KeyCode::VK_LAZY_COMMAND_R, KeyCode::KEY_7, ModifierFlag::SHIFT_L | ModifierFlag::OPTION_L</autogen> </item> </root>
Save the file
- Open in the menulet Karabiner -> Preferences the tab Change Key
- Hit the ReloadXML button
- Enable the remapping. It should be listed at the beginning.
Solution 2:
Why don't you use Karabiner ?
A powerful and stable keyboard customizer for OS X.
You can easily customize from prepared settings.
You can also add your own settings by XML.
https://pqrs.org/osx/karabiner/
Solution 3:
From a brief web search for DefaultKeyBinding.dict
, according to this page:
Only application that [use] Cocoa text system will support this.
This is not a shell file, and will not work when 'source'ed via bash.
Source: @mtklr comment.