Last active
December 1, 2022 17:56
-
-
Save unconditional/bd416f4cb4afdac8d8dec23e1fcfcf15 to your computer and use it in GitHub Desktop.
AutoHotKey script do display current keyboard layout indicator near the cursor when the layout is switched
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. | |
; #Warn ; Enable warnings to assist with detecting common errors. | |
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. | |
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. | |
#SingleInstance, Force | |
CoordMode, Mouse, Screen | |
DefaultIndicatorBackground := 0xffffff | |
LayoutMap := {1033: { Code: 1033, Name: "EN", Color: "c00CC00" } | |
, 1049: { Code: 1049, Name: "RU", Color: "cCC0000" } | |
, 1037: { Code: 1037, Name: "HE", Color: "c0000CC" }} | |
PermanentIndicatorCursorType := "IBeam" | |
LayoutScanPeriod := 300 | |
IndicatorWinTitle := "LangIndicator" | |
Gui, +AlwaysOnTop +Disabled -SysMenu -Caption +Owner | |
Gui, Margin, 5, 5 | |
Gui, Font, s14 cWhite Bold | |
Gui, Add, Text, vLang, "EN" | |
Gui, Color, %DefaultIndicatorBackground% | |
GetActiveLayout() { | |
active_hwnd := WinExist("A") | |
threadID := dllCall("GetWindowThreadProcessId", "uint", active_hwnd, "uint", 0) | |
code := dllCall("GetKeyboardLayout", "uint", threadID, "uint") & 0xFFFF | |
return code | |
} | |
FindLayoutParams(code) { | |
global LayoutMap | |
return LayoutMap[code] | |
} | |
ShowIndicator(color, text, doHide=true) { | |
GuiControl,, Lang, %text% | |
Gui, Color, %color% | |
MouseGetPos, xPos, yPos | |
xPos := xPos + 15 | |
yPos := yPos + 15 | |
Gui, Show, w40 h30 x%xPos% y%yPos% NoActivate, %IndicatorWinTitle% | |
;WinSet, Transparent, 255, %IndicatorWinTitle% | |
if (doHide) { | |
SetTimer, HideIndicator, -1000 | |
} | |
} | |
HideIndicator() { | |
Gui, Cancel | |
} | |
GetCurrentCursor() { | |
return A_cursor | |
} | |
ActiveLayout := GetActiveLayout() | |
PreviousLayout := ActiveLayout | |
LayoutParams := FindLayoutParams(ActiveLayout) | |
ShowIndicator(LayoutParams.Color, LayoutParams.Name) | |
Coursor := GetCurrentCursor() | |
PrevCoursor := Coursor | |
loop { | |
;OutputDebug, %A_Now%: Cursor: %A_cursor% | |
;OutputDebug, % WinExist(%IndicatorWinTitle%) | |
sleep, %LayoutScanPeriod% | |
HideIndicator := false | |
ActiveLayout := GetActiveLayout() | |
Coursor := GetCurrentCursor() | |
if (Coursor != PermanentIndicatorCursorType) { | |
if (PrevCoursor = PermanentIndicatorCursorType) { | |
HideIndicator() | |
} | |
if (ActiveLayout = PreviousLayout) { | |
continue | |
} | |
HideIndicator := true | |
} | |
LayoutParams := FindLayoutParams(ActiveLayout) | |
ShowIndicator(LayoutParams.Color, LayoutParams.Name, HideIndicator) | |
PreviousLayout := ActiveLayout | |
PrevCoursor := Coursor | |
} | |
+esc::exitapp ;press Shift-Escape to close script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment