1

I know I can "cycle through languages" and "toggle between last used two languages" with key combinations. These options are not so convenient when you have three or more input languages installed.

Is there any way to assign a key combination for each language, not cycling or toggling? For the sake of example, if I can press Command + 1 then the input mode is changed to English, if Command + 2 then Japanese, if Command + 3 then Korean. Something like that.

1

1 Answer 1

1

First enable all necessary layouts in System Preferences -> Keyboard -> Input Sources

  1. Download, install and open Karabiner
  2. Open in the menulet Karabiner -> Preferences
  3. Open the tab Misc & Uninstall
  4. Hit the button Open private.xml
  5. Open the file private.xml with an appropriate editor
  6. Enter customized input source definitions and keycodes

    Example:

    <?xml version="1.0"?>
    <root>
    
      <vkchangeinputsourcedef>
        <name>KeyCode::VK_CHANGE_INPUTSOURCE_US</name>
        <inputsourceid_equal>com.apple.keylayout.US</inputsourceid_equal>
      </vkchangeinputsourcedef>
    
      <item>
        <name>Change input source to US by right shift key + U</name>
        <identifier>private.change_input_source_to_us</identifier>
        <autogen>
          __KeyToKey__
          KeyCode::U, ModifierFlag::SHIFT_R,
          KeyCode::VK_CHANGE_INPUTSOURCE_US
        </autogen>
      </item>
    
      <vkchangeinputsourcedef>
        <name>KeyCode::VK_CHANGE_INPUTSOURCE_GERMAN</name>
        <languagecode>de</languagecode>
      </vkchangeinputsourcedef>
    
      <item>
        <name>Change input source to German by right shift key + D</name>
        <identifier>private.change_input_source_to_german</identifier>
        <autogen>
          __KeyToKey__
          KeyCode::D, ModifierFlag::SHIFT_R,
          KeyCode::VK_CHANGE_INPUTSOURCE_GERMAN
        </autogen>
      </item>
    
      <vkchangeinputsourcedef>
        <name>KeyCode::VK_CHANGE_INPUTSOURCE_UNICODEHEXINPUT</name>
        <inputsourceid_equal>com.apple.keylayout.UnicodeHexInput</inputsourceid_equal>
      </vkchangeinputsourcedef>
    
        <item>
        <name>Change input source to HEX by right shift key + H</name>
        <identifier>private.change_input_source_to_hex</identifier>
        <autogen>
          __KeyToKey__
          KeyCode::H, ModifierFlag::SHIFT_R,
          KeyCode::VK_CHANGE_INPUTSOURCE_UNICODEHEXINPUT
        </autogen>
        </item>
    
    </root>
    

    In the example hitting right shiftu will enable the US layout, right shiftg the german layout and right shifth the hex layout.

    A comprehensive list of vkchangeinputsourcedefs is available here.

  7. Save the file

  8. Open in the menulet Karabiner -> Preferences the tab Change Key
  9. Hit the ReloadXML button
  10. Enable all "shortcuts". They are listed at the beginning.
8
  • I tried and it seems to work. I just have one more question. I do not use Apple's Japanese input but Google Japanese Input (a third-party IME tools.google.com/dlpage/japaneseinput/…). How can I get the "identifier" and "inputsourceid_equal" and "languagecode" for Google Japanese IME? Commented Nov 14, 2015 at 10:20
  • @SinJeong-hun Good question. I have to examine this first.
    – klanomath
    Commented Nov 14, 2015 at 10:22
  • @SinJeong-hun The item identifier as well as the item name and probably the vkchangeinputsourcedef KEYCODE name (e.g. VK_CHANGE_INPUTSOURCE_UNICODEHEXINPUT) and the corresponding item KEYCODE (e.g. VK_CHANGE_INPUTSOURCE_UNICODEHEXINPUT) are user defined and have to be unique. So only the inputsourceid_equal and maybe the language code are missing
    – klanomath
    Commented Nov 14, 2015 at 10:36
  • My mistake. I typed "jp" for "languagecode", but it should be "ja". Now, switching to Google Japanese IME works. The only problem is that sometimes (I have not yet found out the exact condition) the IME seems to be switched (flag and check mark changed in the status bar) to Korean but still English is typed. Commented Nov 14, 2015 at 10:37
  • @SinJeong-hun You may try other settings in private.xml
    – klanomath
    Commented Nov 14, 2015 at 10:48

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