MacOS – How to change the input source to different language with shortcut (only one key combination)

keyboardlanguagemacosshortcut

I want to use four language in my OS X system (English, Spanish, Chinese, and Japanese), and I know I can change the language with + Space. However, I have a pathological hatred for switching with it, because it requires me to select from so, so many choices! I also know I can change it from the menubar on the right of the bar, but it's much more disgusting than the + Space solution.

So I rather want to change it with easier shortcut, like the following:

  • left switches to English
  • right switches to Spanish
  • left + left + C switches to Chinese
  • right + right + C switches to Japanese.

I tried to use Karabiner (the descendent from KeyRemap4MacBook), but it doesn't work on the first attempt on Chinese, on which when I switches to Chinese, it remains English (the input source icon on the menubar changes, but the keyboard does not work). But for some reasons if I switch from English to Chinese to English to Chinese (two attempts), then the Chinese keyboard finally works.

So I don't like the idea of using Karabiner. So what is the better way to change the input source?

Best Answer

I ran into the same issue with Chinese and Japanese. (The icon on the menu bar changed but the input source was not actually changed until I switched to another input source and back.) It's a known bug according to a post at Karabiner's mailing list:

It's one of the most annoying bug of OS X.

Changing CJK input sources directly from program is not handled appropriately.

So, you need the following procedures.

Step1:
Enable "Select next source in Input menu" (command-option-space) on System Preferences > Keyboard > Shortcuts.

Step2:
Change input source by sending command-option-space.

<autogen>
  __KeyToKey__
  KeyCode::K, ModifierFlag::OPTION_L,
  KeyCode::VK_CHANGE_INPUTMODE_US,
  KeyCode::VK_WAIT_100MS,
  KeyCode::SPACE, ModifierFlag::COMMAND_R | ModifierFlag::OPTION_L,
  <!-- adjust wait for your machine -->
  KeyCode::VK_WAIT_10MS,
  KeyCode::VK_WAIT_10MS,
  KeyCode::VK_WAIT_10MS,
  KeyCode::SPACE, ModifierFlag::COMMAND_R | ModifierFlag::OPTION_L,
  <!-- adjust wait for your machine -->
  KeyCode::VK_WAIT_10MS,
  KeyCode::VK_WAIT_10MS,
  KeyCode::VK_WAIT_10MS,
  KeyCode::SPACE, ModifierFlag::COMMAND_R | ModifierFlag::OPTION_L,

  Option::NOREPEAT,
</autogen>

changeinput is affected by the same bug.

Another workaround is to just change to another input source and back:

<root>
  <vkchangeinputsourcedef>
    <name>KeyCode::VK_CHANGE_INPUTSOURCE_HIRAGANA</name>
    <inputsourceid_equal>com.apple.inputmethod.Kotoeri.Japanese</inputsourceid_equal>
  </vkchangeinputsourcedef>
  <vkchangeinputsourcedef>
    <name>KeyCode::VK_CHANGE_INPUTSOURCE_SPANISH</name>
    <inputsourceid_equal>com.apple.keylayout.Spanish</inputsourceid_equal>
  </vkchangeinputsourcedef>
  <vkchangeinputsourcedef>
    <name>KeyCode::VK_CHANGE_INPUTSOURCE_US</name>
    <inputsourceid_equal>com.apple.keylayout.US</inputsourceid_equal>
  </vkchangeinputsourcedef>
  <vkchangeinputsourcedef>
    <name>KeyCode::VK_CHANGE_INPUTSOURCE_CHINESE</name>
    <inputsourceid_equal>com.apple.inputmethod.TCIM.Pinyin</inputsourceid_equal>
  </vkchangeinputsourcedef>
  <item>
    <name>inputsources</name>
    <identifier>inputsources</identifier>
    <autogen>__KeyOverlaidModifier__ KeyCode::COMMAND_L, ModifierFlag::COMMAND_L | ModifierFlag::NONE, KeyCode::VK_CHANGE_INPUTSOURCE_US, KeyCode::COMMAND_L</autogen>
    <autogen>__KeyOverlaidModifier__ KeyCode::COMMAND_R, ModifierFlag::COMMAND_R | ModifierFlag::NONE, KeyCode::VK_CHANGE_INPUTSOURCE_SPANISH, KeyCode::COMMAND_R</autogen>
    <autogen>__KeyToKey__ KeyCode::C, ModifierFlag::OPTION_L | ModifierFlag::COMMAND_L | ModifierFlag::NONE, KeyCode::VK_CHANGE_INPUTSOURCE_CHINESE, KeyCode::VK_CHANGE_INPUTSOURCE_US, KeyCode::VK_CHANGE_INPUTSOURCE_CHINESE</autogen>
    <autogen>__KeyToKey__ KeyCode::C, ModifierFlag::OPTION_R | ModifierFlag::COMMAND_R | ModifierFlag::NONE, KeyCode::VK_CHANGE_INPUTSOURCE_HIRAGANA, KeyCode::VK_CHANGE_INPUTSOURCE_US, KeyCode::VK_CHANGE_INPUTSOURCE_HIRAGANA</autogen>
  </item>
</root>