-
-
Save pongo/d916be6b7ce44fdca28b46cadbfb417b to your computer and use it in GitHub Desktop.
So bored to use default keyboard layouts switcher so write mine with ahk
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
en := DllCall("LoadKeyboardLayout", "Str", "00000409", "Int", 1) | |
ru := DllCall("LoadKeyboardLayout", "Str", "00000419", "Int", 1) | |
~<+RControl::SetLayout(ru) | |
~>^LShift::SetLayout(ru) | |
~RControl::SetLayout(en) | |
#Space::ChangeLayout() | |
!Space::ChangeLayout() | |
SetLayout(language) | |
{ | |
ControlGetFocus, control, A | |
PostMessage 0x50, 0, %language%, %control%, A ; WM_INPUTLANGCHANGEREQUEST | |
} | |
ChangeLayout() | |
{ | |
PostMessage 0x50, 2,,, A ; WM_INPUTLANGCHANGEREQUEST | |
} |
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
#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