【问题标题】:get keyboard layout of active window (win 10)获取活动窗口的键盘布局(win 10)
【发布时间】:2018-02-06 14:48:58
【问题描述】:

我使用这个脚本来跟踪 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 上运行吗?

【问题讨论】:

    标签: autohotkey keyboard-layout


    【解决方案1】:

    问题出在这一行:

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

    应该是:

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

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

    【讨论】:

      猜你喜欢
      • 2010-10-14
      • 2014-02-24
      • 1970-01-01
      • 2013-07-19
      • 2021-06-23
      • 2011-12-16
      • 2019-12-09
      • 1970-01-01
      • 2019-01-27
      相关资源
      最近更新 更多