aboutsummaryrefslogtreecommitdiff
path: root/tt.layout.ahk
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-10-23 01:44:02 +0200
committerJohn Ankarström <john@ankarstrom.se>2020-10-23 01:44:02 +0200
commit1f460f7ebc10c2f8bb66ae684498f49187eab9bc (patch)
tree776f7a92b0d24e27cd682e4ff76bde477a02ff98 /tt.layout.ahk
downloadahk-1f460f7ebc10c2f8bb66ae684498f49187eab9bc.tar.gz
first commit
Diffstat (limited to 'tt.layout.ahk')
-rw-r--r--tt.layout.ahk72
1 files changed, 72 insertions, 0 deletions
diff --git a/tt.layout.ahk b/tt.layout.ahk
new file mode 100644
index 0000000..4ce61b0
--- /dev/null
+++ b/tt.layout.ahk
@@ -0,0 +1,72 @@
+;; Quickly change keyboard layout ---------------------------------------------
+
+;; -> body
+
+LWin & LShift::
+LShift & LWin:: ; (my CapsLock is mapped to LWin)
+PostMessage, 0x50, 2, 0,, A ; WM_INPUTLANGCHANGEREQUEST
+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) }
+ShowLayout()
+
+;; -> library
+
+ShowLayout(hwnd := "")
+{
+ global layouts
+ 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")
+ for k, v in layouts
+ {
+ if (layout = v)
+ {
+ if (FileExist(k ".ico"))
+ Menu, Tray, Icon, %k%.ico
+ break
+ }
+ }
+ SetFormat, Integer, %f%
+}
+
+;; 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}"
+}