I've noticed the docs for NumPut() have changed, but in a way that I cannot understand. I've tried to swap the args of the function call around, which did not help fixing the code.
Code: Select all
MsgBox(checkWindowKBD())
checkWindowKBD() {
; Function by Drugwash
threadID := GetFocusedThread(hwnd := WinExist("A"))
hkl := DllCall("user32\GetKeyboardLayout", "UInt", threadID) ; 0 for current thread
; hkl: 1=next, 0=previous | flags: 0x100=KLF_SETFORPROCESS
If !DllCall("user32\ActivateKeyboardLayout", "Ptr", hkl, "UInt", 0x100)
{
;Format("Integer", H)
l := SubStr(hkl & 0xFFFF, 3)
klid := SubStr("00000000" l, -8)
;Format("Integer", D)
; flags: 0x100=KLF_SETFORPROCESS 0x1=KLF_ACTIVATE 0x2=KLF_SUBSTITUTE_OK
DllCall("user32\LoadKeyboardLayoutW", "Str", klid, "UInt", 0x103)
}
DllCall("user32\GetKeyboardLayoutNameW", "Str", klid:="00000000")
; ToolTip("hwndA=" hwnd " -- hkl=" hkl " -- klid=" klid)
Return klid
}
GetFocusedThread(hwnd := 0) {
; Function by Drugwash
If !hwnd
Return 0 ; current thread
tid := DllCall("user32\GetWindowThreadProcessId", "Ptr", hwnd, "Ptr", 0)
VarSetStrCapacity(GTI, sz := 24+6*A_PtrSize) ; GUITHREADINFO struct
; NumPut(Number, VarOrAddress , Offset := 0, Type := "UPtr")
NumPut(sz, GTI, 0, "UInt") ; cbSize
; NumPut(Type, Number, Target , Offset)
;NumPut("UInt", sz, GTI, 0) ; cbSize
If DllCall("user32\GetGUIThreadInfo", "UInt", tid, "Ptr", GTI)
If hF := NumGet(GTI, 8+A_PtrSize, "Ptr")
Return DllCall("user32\GetWindowThreadProcessId", "Ptr", hF, "Ptr", 0)
Return 0 ; current thread (actually it's an error but we couldn't care less)
}