Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Keyboard layout switcher

  • Please log in to reply
17 replies to this topic
  • Members
  • 24 posts
  • Last active: Aug 05 2013 11:34 AM
  • Joined: 09 Oct 2006

My dumb way of doing this translation+switching task: :roll:

; Translates selected text RU<>EN, cycles input language
Pause::Translate() ; Hotkey - Pause button


Send ^{Ins} ; Copy selection to clipboard
r =
Loop, parse, clipboard
	p := InStr(Eng, A_LoopField, true)
	if p > 0
		r := r . SubStr(Rus, p, 1)
		p := InStr(Rus, A_LoopField, true)
		if p > 0
			r := r . SubStr(Eng, p, 1)
			r := r . A_LoopField
PostMessage, 0x50, 2, 0,, A ; Switch lang to next
SendInput {Del}%r% ; Delete selection, print translated text
- only RU<>EN translation
- there must be only two input languages configured, as they are cycled each time


Thank you cargo! The dumbest way is always the safest - I switched over to Autohotkey_L Unicode and the code in the first post stopped working - switching input languages by right ctrl as well as translate text thingy. Replacing it by yours solved all problems!

  • Members
  • 5 posts
  • Last active: Jan 16 2018 09:10 PM
  • Joined: 29 Apr 2010
Yeah, great thing to replace Punto Switcher, yet I'm still sorting out why it does not work on my 64-bit system with 64-bit ahk.
Original script:
If I starts when I have Russian layout, it does not switch layout, showing Russian in tooltip.
If it starts with English layout, it works, but always shows English language in tooltip.
Also, HKL var seem to be always empty.
If I change 4 to A_PtrSize in NumGet and VarSetCapacity, it always switches to different language to what it started with. And HKL, sKbd and sCountry are the same all the time (latter is lang script started with).
Seems that initial HKL:=DllCall("GetKeyboardLayout", "uint",GetThreadOfWindow(), "uint") does not work :(

  • Members
  • 9 posts
  • Last active: Oct 08 2015 05:17 PM
  • Joined: 04 Aug 2013

Here's my En/Ru keyboard layout switch script (Win+Z). For some reason the console (shell) needs a different way to switch layouts correctly.

LOCALE_EN := 0x4090409
LOCALE_RU := 0x4190419
	if WinActive("ahk_class ConsoleWindowClass") {
		PostMessage, 0x50, 0x02, 0,, A
	else {
		SetFormat, Integer, H
		WinGet, WinID,, A
		ThreadID := DllCall("GetWindowThreadProcessId", "UInt", WinID, "UInt", 0)
		InputLocaleID := DllCall("GetKeyboardLayout", "UInt", ThreadID, "UInt")
		PostMessage, 0x50, 0, % ((InputLocaleID == LOCALE_EN) ? LOCALE_RU : LOCALE_EN),, A
		SetFormat, Integer, D