Skip to content

Instantly share code, notes, and snippets.

@bobuk
Created November 1, 2024 14:25
Show Gist options
  • Save bobuk/c6c578ad1db95720f73590f77155605e to your computer and use it in GitHub Desktop.
Save bobuk/c6c578ad1db95720f73590f77155605e to your computer and use it in GitHub Desktop.
So bored to use default keyboard layouts switcher so write mine with ahk
#Requires AutoHotkey v2.0
; Initialize global variables and load keyboard layouts
global ru := DllCall("LoadKeyboardLayout", "Str", "00000419", "Int", 1, "UInt")
global en := DllCall("LoadKeyboardLayout", "Str", "00000409", "Int", 1, "UInt")
; Create a custom combination handler
#HotIf
~LAlt & LWin:: ; Left Alt being held and Left Win pressed
~LWin & LAlt:: ; Left Win being held and Left Alt pressed
{
; Get the foreground window and its keyboard layout
w := DllCall("GetForegroundWindow", "Ptr")
if !w {
return ; Exit if no window is found
}
pid := DllCall("GetWindowThreadProcessId", "Ptr", w, "Ptr", 0, "UInt")
if !pid {
return ; Exit if no process ID is found
}
l := DllCall("GetKeyboardLayout", "UInt", pid, "UPtr")
if !l {
return ; Exit if no keyboard layout is found
}
; Switch keyboard layout
if (l = en) {
result := PostMessage(0x50, 0, ru,, "A") ; WM_INPUTLANGCHANGEREQUEST
} else {
result := PostMessage(0x50, 0, en,, "A")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment