Friday 21 February 2014

Convenient keyboard layout switching for 3 or more languages in Linux.

I'm using four different keyboard layouts at a semi-regular basis. Switching between them used to be a headache until I came up with the idea of assigning each language a separate key shorcut consisting of a home row character + the Windows(Meta) key.

Since each layout has a separate shortcut, I no longer need to remember what locale I'm currently using and then count how many times I need to press the universal switch key in order to switch to the desired language. In addition, I don't have to move my fingers from the home row except for the pinky to reach the Windows key.

I implemented my scheme on Linux using ibus as the input method framework, xbindkeys as the keyboard shortcut manager and xbindkeysrc-config for config creation.

After installing these components you need to make a config file for xbindkeys (~/.xbindkeysrc) that would define the keyboard shortcuts and locales. Mine turned out to be as follows:
#Japanese
# The new ibus version does not switch from Cyrillic to Japanese for some reason, so we have to switch to English first.
# Replace "anthy" with "mozc-jp" if you're using Mozc.
"ibus engine xkb:us::eng; ibus engine anthy"
m:0x40 + c:44

#English
"ibus engine xkb:us::eng"
m:0x40 + c:45

#Russian
"ibus engine xkb:ru::rus"
m:0x40 + c:46

#Ukrainian
"ibus engine xkb:ua::ukr"
m:0x40 + c:32

#French
"ibus engine xkb:fr::fra"
m:0x40 + c:47
"ibus engine ..." is the console command that makes ibus switch the current layout. Using keycodes is necessary since the same physical keys may represent different characters in different locales.

<LWin+k>Layout switching became easy!
<LWin+j>入力言語の切り替えは簡単になりました!
<LWin+l>Переключение языков стало простым!
<LWin+;>Changement de langue est devenu très simple!

P.S. I think the same result should be achievable in Windows using the AutoHotkey tool, though I haven't looked into it.