You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取Windows键盘布局描述信息?Python开发求助

获取Windows已安装键盘布局的描述信息问题

我正在用Python开发一款Windows应用,需要获取系统中所有已安装的键盘布局:
Windows布局选择器界面

我已经通过Win32 API的GetKeyboardLayoutList和GetLocaleInfoW实现了基础功能:
终端显示布局名称列表

但仍缺少所谓的「描述信息」(即第一张截图中的“Microsoft IME”或“German”这类显示内容)。

现有实现代码

获取所有布局的函数

import ctypes

user32 = ctypes.windll.user32

def get_all_layouts() -> None:
    n_layouts = user32.GetKeyboardLayoutList(0, None)
    buffer = (ctypes.c_ulong * n_layouts)()
    user32.GetKeyboardLayoutList(n_layouts, ctypes.byref(buffer))
    layouts = []

    for layout in buffer:
        layout_id = layout & 0xFFFF
        layout_name = get_layout_name(layout_id)
        layout_description = get_layout_description(layout_id)

        if layout_name:
            layouts.append({
                'name': layout_name,
                'description': layout_description
            })
            continue

        print('Failed to get layout name')

    return layouts

对应的get_layout_name函数

import ctypes

user32 = ctypes.windll.user32
LOCALE_SLANGUAGE = 0x00000002

def get_layout_name(layout: int) -> str:
    name = ctypes.create_unicode_buffer(256)

    if ctypes.windll.kernel32.GetLocaleInfoW(layout, LOCALE_SLANGUAGE, name, 256):
        return name.value

    return ''

目前get_layout_description函数为空。我已查阅微软官方的区域设置信息相关文档,尝试过GetKeyNameTextW、GetKeyboardLayoutNameW等函数,以及结合LoadKeyboardLayoutW/ActivateKeyboardLayout与GetKeyboardLayout的方式,但均未得到正确结果或无返回。


内容的提问来源于stack exchange,提问作者Surge

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 20:23:25