Code: Select all
; v1
SetDefaultKeyboard(LocaleID){
Global
SPI_SETDEFAULTINPUTLANG := 0x005A
SPIF_SENDWININICHANGE := 2
Lan := DllCall("LoadKeyboardLayout", "Str", Format("{:08x}", LocaleID), "Int", 0)
VarSetCapacity(Lan%LocaleID%, 8, 0)
NumPut(LocaleID, Lan%LocaleID%)
DllCall("SystemParametersInfo", "UInt", SPI_SETDEFAULTINPUTLANG, "UInt", 0, "UPtr", &Lan%LocaleID%, "UInt", SPIF_SENDWININICHANGE)
WinGet, windows, List
Loop %windows% {
PostMessage 0x50, 0, %Lan%, , % "ahk_id " windows%A_Index%
}
}
return
Code: Select all
; v2
SetDefaultKeyboardLang(LocaleID)
{
Static SPI_SETDEFAULTINPUTLANG := 0x005A, SPIF_SENDWININICHANGE := 2
Lan := DllCall("LoadKeyboardLayout", "Str", Format("{:08x}", LocaleID), "Int", 0)
binaryLocaleID := Buffer(8,0)
NumPut("UPtr",LocaleID, binaryLocaleID)
DllCall("SystemParametersInfo", "UInt", SPI_SETDEFAULTINPUTLANG, "UInt", 0, "UPtr", binaryLocaleID, "UInt", SPIF_SENDWININICHANGE)
owindows := WinGetList(,,,)
Loop owindows.Length
PostMessage 0x50, 0, Lan, , "ahk_id " windows[A_Index]
}
Is there some incorrect conversion? (There is a warning saying this, but seeing the docs, I don't understand why there is a warning [In the image it shows just "", but it is "UPtr"]) I also have another function for changing the language. What is the difference between SetDefaultKeyboard and SetInputLang? SetDefaultKeyboard(0x10409) works in v1 as intended so why does SetInputLang(0x10409) not work in v2 or v1? That is the LocaleID of Dvorak (Standard).
Code: Select all
SetInputLang(Lang)
{
PostMessage 0x50, 0, Lang, , "A"
}
Code: Select all
SetDefaultKeyboardLang(LocaleID)
{
Lan := DllCall("LoadKeyboardLayout", "Str", Format("{:08x}", LocaleID), "Int", 0)
owindows := WinGetList(,,,)
Loop owindows.Length
PostMessage 0x50, 0, Lan, , "ahk_id " owindows[A_Index]
}
Even with the DllCall warning (binLocId = Buffer(8, 0)), the language gets changed for some reason.
I changed the byte size of the Buffer which removed the NumPut warning.