Toggle the keyboard language by *holding* a button?

On my Linux computer, my keyboard switches from English to Serbian when I hold the Caps Lock key. For example, to write č all I have to do is hold Caps Lock, and press the key where č is on the Serbian keyboard (in this case, they key is ; on the English keyboard). When I release Caps Lock, the keyboard "switches back" to English, so that if I press ; I get ; as desired. Super useful.

Is there a way to replicate this behavior on OS X?


You can use KeyRemap4MacBook:

<?xml version="1.0"?>
<root>
  <vkchangeinputsourcedef>
    <name>KeyCode::VK_CHANGE_INPUTSOURCE_SERBIAN</name>
    <inputsourceid_equal>com.apple.keylayout.Serbian</inputsourceid_equal>
  </vkchangeinputsourcedef>
  <item>
    <name>test</name>
    <identifier>test</identifier>
    <autogen>__KeyToKey__ KeyCode::F1, KeyCode::VK_NONE, Option::KEYTOKEY_BEFORE_KEYDOWN, KeyCode::VK_CHANGE_INPUTMODE_SERBIAN, Option::KEYTOKEY_AFTER_KEYUP, KeyCode::VK_CHANGE_INPUTMODE_ENGLISH</autogen>
  </item>
</root>

VK_CHANGE_INPUTMODE_ENGLISH is defined in inputsourcedef.xml. You can see the IDs of input sources from EventViewer.app. Caps lock can be remapped to an F-key with PCKeyboardHack.


If you're on 10.7 Lion or newer, you can also press the c key down until it shows a list of all c characters with various decorations.