     }
     return
 }
-
 OnClipboardChange("ClipboardChanged")
 
+
+;enforce same keyboard layout across all programs
+global Locale1 := 0x4150415
+global Locale2 := 0x4110411
+global CurrentLocale := Locale1
+
+GetActiveLocale()
+{
+    win_id := WinGetID("A")
+    thread_id := DllCall("GetWindowThreadProcessId", "Int", win_id, "Int", "0")
+    return DllCall("GetKeyboardLayout", "Int", thread_id)
+}
+
+ApplyLocale(locale)
+{
+    global CurrentLocale := locale
+    SendMessage(0x50, 0, locale, "", "A")
+}
+
+CycleLocale()
+{
+    if CurrentLocale == Locale1 {
+        ApplyLocale(locale2)
+    } else if CurrentLocale == Locale2 {
+        ApplyLocale(Locale1)
+    }
+}
+
+ShellMessage(wparam, lparam)
+{
+    title := WinGetTitle(lparam)
+    if wParam == 4 { ;HSHELL_WINDOWACTIVATED
+        ApplyLocale(CurrentLocale)
+    }
+}
+
+gui := GuiCreate("", "")
+gui.Opt("+LastFound")
+hwnd := WinExist()
+DllCall("RegisterShellHookWindow", uint, hwnd)
+msgnum := DllCall("RegisterWindowMessage", str, "SHELLHOOK")
+OnMessage(msgnum, "ShellMessage")
+
+
 return
+
 
 #If FileExist(CygPath)
     ;cygwin - activate/run

    return
}

;fix URLs copied by some browsers so they're clickable in popular programs
ClipboardChanged(Type)
{
    if (SubStr(clipboard, 1, 7) == "http://") || SubStr(clipboard, 1, 8) == "https://" {
        clipboard := StrReplace(clipboard, "[", "%5b", All)

A_CoordModeMouse := "Screen"
A_CoordModeToolTip := "Screen"


;detect cygwin
CygPath := "C:\Program Files (x86)\cygwin"
if !FileExist(CygPath) {
