From 849c58ab89117c45d0b40db23da42117a0b68f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 26 Dec 2020 15:45:37 +0100 Subject: layout: Define explicitly which layouts to toggle between --- tt.layout.ahk | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'tt.layout.ahk') diff --git a/tt.layout.ahk b/tt.layout.ahk index 54821db..824f3fa 100644 --- a/tt.layout.ahk +++ b/tt.layout.ahk @@ -3,7 +3,19 @@ ;; -> body LWin & Tab:: -PostMessage, 0x50, 2, 0,, A ; WM_INPUTLANGCHANGEREQUEST +if (GetKeyState("Shift")) + new := altlayout +else +{ + new := activelayouts[1] + current := Layout() + for k, v in activelayouts + { + if (v = current) + new := activelayouts[k+1] + } +} +DllCall("SendMessage", "UInt", WinActive("A"), "UInt", 80, "UInt", 1, "UInt", new) Sleep, 100 ShowLayout() ; display new layout in tray icon return @@ -13,30 +25,39 @@ return ;; -> init layouts := { ru: DllCall("LoadKeyboardLayout", "Str", "00000419", "Int", 1) - , sv: DllCall("LoadKeyboardLayout", "Str", "0000041D", "Int", 1) } + , sv: DllCall("LoadKeyboardLayout", "Str", "0000041D", "Int", 1) + , us: DllCall("LoadKeyboardLayout", "Str", "00000409", "Int", 1) } +activelayouts := [layouts.us, layouts.ru] +altlayout := layouts.sv + ShowLayout() ;; -> library -ShowLayout(hwnd := "") -{ - global layouts +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 + Menu, Tray, Icon, %k%.ico break } } - SetFormat, Integer, %f% } ;; Update layout display on window change ------------------------------------- -- cgit v1.2.3