获取活动窗口的键盘布局(赢10)

时间:2018-02-06 14:48:58

标签: autohotkey keyboard-layout

我使用这个脚本来跟踪Win 7上的键盘布局,它运行正常:

getactiveKL() {
    active_hwnd := WinExist("A")
    threadID := dllCall("GetWindowThreadProcessId", "uint", active_hwnd)
    code := dllCall("GetKeyboardLayout", "uint", threadID, "uint") & 0xFFFF
    return code
}
; 1049 - RU (hex: 419)
; 1033 - EN (hex: 409)

loop {
    sleep, 600
    KL := getactiveKL()
    tooltip, %KL%
}

但它不会对win 10起作用。即它只能运行一次 - 如果我将布局设置为RU,然后运行此脚本,它会正确检测到,但是当我切换布局时 - 没有任何变化。
你知道如何让它在Windows 10上运行吗?

1 个答案:

答案 0 :(得分:1)

问题在于这一行:

threadID := dllCall("GetWindowThreadProcessId", "uint", active_hwnd, "uint", 0)

应该是:

onYouTubeIframeAPIReady()

网上有很多例子,这个dll调用的拼写不同,所以后者在Windows 10上正常工作。