The script does not change the input language in some windows

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Yurimi
Posts: 2
Joined: 27 Nov 2018, 16:35

The script does not change the input language in some windows

07 Dec 2018, 17:35

Hello. I have this script:

Code: Select all

   ;--------------------; Keyboard Layout for Language ;--------------------;
 ; For [LAlt]+[LShift] Button key
#IfWinActive
~LAlt & ~LShift::
	SetFormat, Integer, H
	LocaleRussian=0x4090409		; English Language
	LocaleEnglish=0x4190419		; Russian Language
	LocaleWinID := WinExist("A")
	ThreadID:=DllCall("GetWindowThreadProcessId", "Int", LocaleWinID, "Int", "0")
	InputLocaleID:=DllCall("GetKeyboardLayout", "Int", ThreadID)

	If(InputLocaleID!=LocaleRussian)
	{
		PostMessage, 0x50,, % LocaleRussian,, A
	}
	Else
	{
		If(InputLocaleID!=LocaleEnglish)
			PostMessage, 0x50,, % LocaleEnglish,, A
	}
	Return

 ; For [LShift]+[LAlt] Button key
#IfWinActive
~LShift & ~LAlt::
	SetFormat, Integer, H
	LocaleRussian=0x4090409		; English Language
	LocaleEnglish=0x4190419		; Russian Language
	LocaleWinID := WinExist("A")
	ThreadID:=DllCall("GetWindowThreadProcessId", "Int", LocaleWinID, "Int", "0")
	InputLocaleID:=DllCall("GetKeyboardLayout", "Int", ThreadID)

	If(InputLocaleID!=LocaleRussian)
	{
		PostMessage, 0x50,, % LocaleRussian,, A
	}
	Else
	{
		If(InputLocaleID!=LocaleEnglish)
			PostMessage, 0x50,, % LocaleEnglish,, A
	}
	Return

 ; For [LControl]+[LAlt] Button key
#IfWinActive
~LControl & ~LAlt::
	LocaleJapan=0x4110411		; Japan Language
	PostMessage, 0x50,, % LocaleJapan,, A
	Sleep 50
	Send !{CapsLock}		; Katakana
	Return

 ; For [LAlt]+[LControl] Button key
#IfWinActive
~LAlt & ~LControl::
	LocaleJapan=0x4110411		; Japan Language
	PostMessage, 0x50,, % LocaleJapan,, A
	Sleep 50
	Send ^{CapsLock}		; Hiragana
	Return
 ;;;
In most applications, the script changes the input language, but when I select some windows active, for example: “Find” in Notepad ++ or cmd console - the script does not change the input language, even though it finds a window and checks the language. This problem also applies to any other "dialog boxes" (for example, those that can be call in the browser by clicking "Save As")
The problem, as I see it, is related to PostMessage . I don’t know how to fix this problem, I don’t have much experience with ahk, I know about the wiki, but I couldn’t resolve my problem with wiki help. Also I already tried to ask in the section in forum with my native language, but nobody answered me. I hope for your help;

P.S. Additional, not so important questions-
1) Is it possible to specify input methods when changing the input language? In order not to put Hiragana or Katakana through keyboard hotkeys, but do something as PostMessage?
2) Can I combine ~LAlt & ~LShift и ~LShift & ~LAlt into one key combination? They had to be duplicated with changeable order, because this order of pressing the key is important for their performance.

Thank you for your time
eugenesv
Posts: 174
Joined: 21 Dec 2015, 10:11

Re: The script does not change the input language in some windows

07 Dec 2020, 15:02

I know it's been a while since your post and hopefuly you've resolved all your input language issues by now, but I've recently decided to fix the same issues for me and while searching for answers found your post with the same question, so I though I might share my solution here as well:
Get/Set input/keyboard layout in Console/UWP/Steam/Dialog windows[a122]
It'd need to be modified to precisely match your example, but at least it gives you the idea on how to fix Consoles and Dialog windows when both getting and setting input layouts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, jaka1, rc76 and 307 guests