It works well when the window is not minimized, But there is a simple and weird problem when the window is minimized :
- For ex, when the specific window (Visual Studio Code) is Not Minimized the script performs well the desired operation, But when the window is minimized and the current keyboard layout language is Arabic (for ex), and I wanted to restore the window (by click on the task bar icon) and automatically the language changes to English, When I restore the window (by click on the task bar icon), the current input language does not change automatically from the first time (restoring), but when I minimize it again then restore it from the second time, the input language changes automatically to English.
- Could someone make the script do the desired operation from the first time (restoring) when the window is minimized?
- Another question, How do I put the Process name or the window class ... in stead of the window title?
- If there is any other script that performs the desired operation, please give it to me.
- Please help! I appreciate your time and effort. Thanks in advance.
- This is the Autohotkey script :
Code: Select all
; =====================================================================
; You can use the function at the end of the code to find the ID of the current keyboard layout language.
; Cultures can be fetched from here: https://msdn.microsoft.com/en-us/library/windows/desktop/dd318693(v=vs.85).aspx
; They must be set twice in the language ID;
; Ar-TN: "0xf0291c01" this is the ID for the Arabic Tunisia keyboard layout language.
; En-US: "0x4090409" this is the ID for the English US keyboard layout language.
global DefaultLanguage := "Ar-TN"
global DefaultLanguageIndentifier := "0xf0291c01"
global SecondaryLanguage := "En-US"
global SecondaryLanguageIndentifier := "0x4090409"
global SecondaryLanguageWindowTitles := "Visual Studio"
; And the code itself (you should not have to change this)
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,Hwnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return
ShellMessage( wParam,lParam )
{
WinGetTitle, title, ahk_id %lParam%
; 4 is HSHELL_WINDOWACTIVATED, 32772 is HSHELL_RUDEAPPACTIVATED
If (wParam=4 || wParam=32772) {
If title contains %SecondaryLanguageWindowTitles%
SetKeyboard( title, SecondaryLanguage )
Else
SetKeyboard( title, DefaultLanguage )
}
}
SetKeyboard( title, culture )
{
; 0x50 is WM_INPUTLANGCHANGEREQUEST.
Try
{
If (culture = SecondaryLanguage)
{
PostMessage, 0x50, 0, %SecondaryLanguageIndentifier%,, A
; To debug:
; ToolTip, Using secondary language %SecondaryLanguage%
; Sleep 1000
; ToolTip
}
Else (culture = DefaultLanguage)
{
PostMessage, 0x50, 0, %DefaultLanguageIndentifier%,, A
; To debug:
; ToolTip, Using default language %DefaultLanguage%
; Sleep 1000
; ToolTip
}
}
}
; .....................................................................
; You can use this to find the id of the current language:
^i::MsgBox, % GetDefaultKeyboard()
; get default keyboard language
GetDefaultKeyboard() {
ThreadID := DllCall("GetWindowThreadProcessId", "UInt", WinExist("A"), "UInt", 0)
InputLocaleID := DllCall("GetKeyboardLayout", "UInt", ThreadID, "UInt")
return Format("{:#x}", InputLocaleID)
}
; =====================================================================