#NoEnv #KeyHistory, 0 #SingleInstance, Ignore ListLines, Off IfEqual, A_IsAdmin, % False, Run, % "*RunAs `"`""A_ScriptFullPath "`"`"",, UseErrorLevel IfEqual, A_IsAdmin, % False, ExitApp ListLines, On ;~ MButton::SendWindowMessage() ~LAlt:: (hWndPrev<>hWnd:=WinActive("A")) And (hWndPrev:=hWnd, uId:=CheckUpCharacterCode(hWnd)) , ((curId:=CheckUpLayout(hWnd))<>uId And uId) And (bState:=True, SendWindowMessage(hWnd, uId)) KeyWait, LAlt Exit, (bState) And SendWindowMessage(hWnd, curId), bState:=hWnd:=curId:=A_EndChar CheckUpCharacterCode(p) { If hMenu:=DllCall("GetMenu", "UPtr", p, "UPtr") { DllCall("GetMenuString"(A_IsUnicode ? "W":"A"), "UPtr", hMenu , "UInt", 0 , "UPtr", 0*VarSetCapacity(buf, nMaxCount :=DllCall("GetMenuString"(A_IsUnicode ? "W":"A"), "UPtr", hMenu , "UInt", 0 , "UPtr", 0 , "Int", 0 , "UInt", 0x00000400 ; MF_BYPOSITION , "Int") *(A_IsUnicode ? 2:1)+1, 0)|&buf , "Int", nMaxCount , "UInt", 0x00000400) charNumber:=Asc(RegExReplace(StrGet(&buf), ".*&([A-zА-я]).*", "$1")) If charNumber Between 65 And 122 Return, 0x04090409 Else If charNumber Between 1040 And 1103 Return, 0x04190419 } Return, 0x00000000 } CheckUpLayout(p) { Return, DllCall("GetKeyboardLayout", "UInt", DllCall("GetWindowThreadProcessId", "UPtr", p , "UInt*", 0 , "UInt") , "UPtr") } SendWindowMessage(p1:=0, p2:=0) { DllCall("SendMessage"(A_IsUnicode ? "W":"A"), "UPtr", p1 ? p1:WinActive("A") , "UInt", 0x0050 ; WM_INPUTLANGCHANGEREQUEST , "Ptr", p2 ? 0:0x0002 ; INPUTLANGCHANGE_FORWARD , "Ptr", p2 ? p2:0) } |