aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-12-26 15:45:37 +0100
committerJohn Ankarström <john@ankarstrom.se>2020-12-26 15:45:37 +0100
commit849c58ab89117c45d0b40db23da42117a0b68f71 (patch)
tree94de92a818da42eb8d69657d371de9b4a4b3d2e8
parent04b865477e8d52dac294db647bcf41234d9fd6f2 (diff)
downloadahk-849c58ab89117c45d0b40db23da42117a0b68f71.tar.gz
layout: Define explicitly which layouts to toggle between
-rw-r--r--tt.layout.ahk35
1 files changed, 28 insertions, 7 deletions
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 -------------------------------------