;; Quickly change keyboard layout --------------------------------------------- ;; -> body ^\:: ^+\:: if (GetKeyState("Shift")) new := altlayout else { new := activelayouts[1] current := Layout() for k, v in activelayouts { if (v = current) new := activelayouts[k+1] } if (new = "") new := activelayouts[1] } DllCall("SendMessage", "UInt", WinActive("A"), "UInt", 80, "UInt", 1, "UInt", new) Sleep, 100 ShowLayout() ; display new layout in tray icon return ;; Display keyboard layout in tray icon --------------------------------------- ;; -> init layouts := { ru: DllCall("LoadKeyboardLayout", "Str", "00000419", "Int", 1) , sv: DllCall("LoadKeyboardLayout", "Str", "0000041D", "Int", 1) , us: DllCall("LoadKeyboardLayout", "Str", "00000409", "Int", 1) , jp: DllCall("LoadKeyboardLayout", "Str", "00000411", "Int", 1) } activelayouts := [layouts.us, layouts.jp] altlayout := layouts.ru ShowLayout() ;; -> library Layout() { f := A_FormatInteger SetFormat, Integer, H if (hwnd = "") WinGet, hwnd, id, A thread := DllCall("GetWindowThreadProcessId", "UInt",hwnd, "UInt",0) layout := DllCall("user32.dll\GetKeyboardLayout", "UInt",thread, "UInt") SetFormat, Integer, %f% return layout } ShowLayout(hwnd := "") { global layouts layout := Layout() for k, v in layouts { if (layout = v) { if (FileExist(k ".ico")) Menu, Tray, Icon, %k%.ico break } } } ;; Update layout display on window change ------------------------------------- ;; -> library LayoutWindowMessage(wParam, lParam) { if (wParam = 4 or wParam = 32772) ; HSHELL_WINDOW_ACTIVATED | HSHELL_RUDEAPPACTIVATED { ShowLayout(lParam) WinSet, AlwaysOnTop, On, OSD } } ;; -> init WindowMessageHandlers.Push("LayoutWindowMessage") ;; Click tray icon to open Text Services and Input Languages ------------------ ;; -> init OnMessage(0x404, "NotifyIcon") ;; -> library NotifyIcon(wParam, lParam) { if (lParam = 0x202) ; WM_LBUTTONUP Run, % "Rundll32 Shell32.dll,Control_RunDLL input.dll,,{C07337D3-DB2C-4D0B-9A93-B722A6C106E2}" }