Windows – switch input methods while Caps Lock is being held down on Windows

input-languageswindows

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.

Please note that I know how to change the keyboard layout. I want to use Caps Lock as a modifier key to change the language only while being held down!

Is there a way to replicate this behavior on Windows 7 or Windows 8?

Remark: This is sometimes known as "third level" character switching (pressing shift would be second level, for example). I am also not that attached to Caps Lock; other keys will do.

Best Answer

Most reliable AutoHotKey script from my testing was this:

*CapsLock::
SetKeyDelay -1   ; If the destination key is a mouse button, SetMouseDelay is used instead.
;send {Blind}{CapsLock DownTemp}
PostMessage, 0x50, 0x02, 1,, A ; 0x50 is WM_INPUTLANGCHANGEREQUEST. 0x02 is forward
return

*CapsLock up::
SetKeyDelay -1  ; See note below for why press-duration is not specified with either of these SetKeyDelays.
;send {Blind}{CapsLock Up}
PostMessage, 0x50, 0x04, 1,, A ; 0x50 is WM_INPUTLANGCHANGEREQUEST. 0x04 is backward
return

Note: you need to have 2 input languages already set up in the windows region/language control panel.

Stand alone executable version here.

To stop the script, right click on the H in your task bar and click pause/exit.

If you want to retain the functionality of caps lock (ie: pressing it will turn caps lock on AND change language, releasing it will revert to previous language but leave caps lock on) just remove the two ; characters at the start of the two send lines.

Watch how fast i type this: ;č;č;č;č;č;č;č;č

Pretty fast, huh?

Related Question