如何获取键盘名称? (以视觉区分特定语言的键盘)
How to get keyboard name? (to visually distinguish keyboards in a specific language)
例如,我安装了 2 种语言 — 英语和俄语。俄语有 2 个键盘——普通和助记键:
当我运行代码:
UINT uLayouts;
HKL *lpList = NULL;
wchar_t szBufLng[512], szBufCtry[512];
uLayouts = GetKeyboardLayoutList(0, NULL);
lpList = (HKL*)LocalAlloc(LPTR, (uLayouts * sizeof(HKL)));
uLayouts = GetKeyboardLayoutList(uLayouts, lpList);
for(int i = 0; i < uLayouts; ++i)
{
GetLocaleInfo(MAKELCID(((UINT)lpList[i] & 0xffffffff),
SORT_DEFAULT), LOCALE_SISO639LANGNAME, szBufLng, 512);
GetLocaleInfo(MAKELCID(((UINT)lpList[i] & 0xffffffff),
SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, szBufCtry, 512);
wprintf(L"%s-%s, %x\n", szBufLng, szBufCtry, (UINT)lpList[i]);
memset(szBufLng, 0, 512);
memset(szBufCtry, 0, 512);
}
if(lpList)
LocalFree(lpList);
我得到以下结果:
en-US, 04090409
ru-RU, 04190419
ru-RU, f0330419
我的问题是如何区分助记词?
至少要显示这样的内容:
en-US, 04090409
ru-RU, 04190419
rum-RU, f0330419
如何获取键盘名称?
同样的问题在这里讨论(无解):
https://forums.codeguru.com/showthread.php?492287-Keyboard-Layout-Name
我在 Windows 10 中从注册表(\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard 布局)导出数据,并基于它创建了一个 table。并借助 SHLoadIndirectString 获得了键盘的本地化名称。
struct LAYOUT_KEYBOARD_INFO {
LCID layout_id;
short display_name_id;
wchar_t default_keyboard_name[64];
};
LAYOUT_KEYBOARD_INFO LAYOUT_KEYBOARDS[] = {
{0x0401, 5084, L"Arabic (101)"},
{0x0402, 5053, L"Bulgarian (Typewriter)"},
{0x0404, 5065, L"Chinese (Traditional) - US Keyboard"},
{0x0405, 5031, L"Czech"},
{0x0406, 5007, L"Danish"},
{0x0407, 5011, L"German"},
{0x0408, 5046, L"Greek"},
{0x0409, 5000, L"US"},
{0x040A, 5020, L"Spanish"},
{0x040B, 5009, L"Finnish"},
{0x040C, 5010, L"French"},
{0x040D, 5083, L"Hebrew"},
{0x040E, 5033, L"Hungarian"},
{0x040F, 5013, L"Icelandic"},
{0x0410, 5015, L"Italian"},
{0x0411, 5061, L"Japanese"},
{0x0412, 5063, L"Korean"},
{0x0413, 5008, L"Dutch"},
{0x0414, 5018, L"Norwegian"},
{0x0415, 5035, L"Polish (Programmers)"},
{0x0416, 5003, L"Portuguese (Brazilian ABNT)"},
{0x0418, 5037, L"Romanian (Legacy)"},
{0x0419, 5055, L"Russian"},
{0x041A, 5030, L"Standard"},
{0x041B, 5039, L"Slovak"},
{0x041C, 5029, L"Albanian"},
{0x041D, 5022, L"Swedish"},
{0x041E, 5079, L"Thai Kedmanee"},
{0x041F, 5060, L"Turkish Q"},
{0x0420, 5129, L"Urdu"},
{0x0422, 5058, L"Ukrainian"},
{0x0423, 5052, L"Belarusian"},
{0x0424, 5041, L"Slovenian"},
{0x0425, 5042, L"Estonian"},
{0x0426, 5043, L"Latvian"},
{0x0427, 5045, L"Lithuanian IBM"},
{0x0428, 5151, L"Tajik"},
{0x0429, 5124, L"Persian"},
{0x042A, 5118, L"Vietnamese"},
{0x042B, 5120, L"Armenian Eastern"},
{0x042C, 5117, L"Azeri Latin"},
{0x042E, 5163, L"Sorbian Standard (Legacy)"},
{0x042F, 5109, L"Macedonian (FYROM)"},
{0x0432, 5191, L"Setswana"},
{0x0437, 5119, L"Georgian"},
{0x0438, 5108, L"Faeroese"},
{0x0439, 5096, L"Devanagari - INSCRIPT"},
{0x043A, 5140, L"Maltese 47-Key"},
{0x043B, 5138, L"Norwegian with Sami"},
{0x043F, 5113, L"Kazakh"},
{0x0440, 5128, L"Kyrgyz Cyrillic"},
{0x0442, 5150, L"Turkmen"},
{0x0444, 5116, L"Tatar (Legacy)"},
{0x0445, 5135, L"Bengali"},
{0x0446, 5101, L"Punjabi"},
{0x0447, 5097, L"Gujarati"},
{0x0448, 5100, L"Oriya"},
{0x0449, 5102, L"Tamil"},
{0x044A, 5103, L"Telugu"},
{0x044B, 5098, L"Kannada"},
{0x044C, 5139, L"Malayalam"},
{0x044D, 5177, L"Assamese - INSCRIPT"},
{0x044E, 5104, L"Marathi"},
{0x0450, 5127, L"Mongolian Cyrillic"},
{0x0451, 5154, L"Tibetan (PRC)"},
{0x0452, 5145, L"United Kingdom Extended"},
{0x0453, 5161, L"Khmer"},
{0x0454, 5162, L"Lao"},
{0x045A, 5130, L"Syriac"},
{0x045B, 5166, L"Sinhala"},
{0x045C, 5209, L"Cherokee Nation"},
{0x0461, 5169, L"Nepali"},
{0x0463, 5159, L"Pashto (Afghanistan)"},
{0x0465, 5132, L"Divehi Phonetic"},
{0x0468, 5187, L"Hausa"},
{0x046A, 5189, L"Yoruba"},
{0x046C, 5186, L"Sesotho sa Leboa"},
{0x046D, 5148, L"Bashkir"},
{0x046E, 5168, L"Luxembourgish"},
{0x046F, 5170, L"Greenlandic"},
{0x0470, 5188, L"Igbo"},
{0x0474, 5231, L"Guarani"},
{0x0475, 5198, L"Hawaiian"},
{0x0480, 5165, L"Uyghur (Legacy)"},
{0x0481, 5146, L"Maori"},
{0x0485, 5160, L"Sakha"},
{0x0488, 5190, L"Wolof"},
{0x0492, 5199, L"Central Kurdish"},
{0x0804, 5072, L"Chinese (Simplified) - US Keyboard"},
{0x0807, 5024, L"Swiss German"},
{0x0809, 5025, L"United Kingdom"},
{0x080A, 5017, L"Latin American"},
{0x080C, 5002, L"Belgian French"},
{0x0813, 5001, L"Belgian (Period)"},
{0x0816, 5019, L"Portuguese"},
{0x081A, 5038, L"Serbian (Latin)"},
{0x082C, 5115, L"Azeri Cyrillic"},
{0x083B, 5144, L"Swedish with Sami"},
{0x0843, 5114, L"Uzbek Cyrillic"},
{0x0850, 5158, L"Mongolian (Mongolian Script)"},
{0x085D, 5156, L"Inuktitut - Latin"},
{0x085F, 5229, L"Central Atlas Tamazight"},
{0x0C04, 5192, L"Chinese (Traditional, Hong Kong S.A.R.) - US Keyboard"},
{0x0C0C, 5005, L"Canadian French (Legacy)"},
{0x0C1A, 5057, L"Serbian (Cyrillic)"},
{0x0C51, 5235, L"Dzongkha"},
{0x1004, 5193, L"Chinese (Simplified, Singapore) - US Keyboard"},
{0x1009, 5004, L"Canadian French"},
{0x100C, 5023, L"Swiss French"},
{0x105F, 5207, L"Tifinagh (Basic)"},
{0x1404, 5194, L"Chinese (Traditional, Macao S.A.R.) - US Keyboard"},
{0x1809, 5014, L"Irish"},
{0x201A, 5155, L"Bosnian (Cyrillic)"},
{0x4009, 5196, L"India"},
// Added F to "Layout Id"
{0xF028, 5085, L"Arabic (102)"},
{0xF004, 5054, L"Bulgarian (Latin)"},
{0xF005, 5032, L"Czech (QWERTY)"},
{0xF012, 5012, L"German (IBM)"},
{0xF016, 5048, L"Greek (220)"},
{0xF002, 5092, L"United States-Dvorak"},
{0xF086, 5021, L"Spanish Variation"},
{0xF006, 5034, L"Hungarian 101-key"},
{0xF003, 5016, L"Italian (142)"},
{0xF007, 5036, L"Polish (214)"},
{0xF010, 5126, L"Portuguese (Brazilian ABNT2)"},
{0xF0A5, 5175, L"Romanian (Standard)"},
{0xF008, 5056, L"Russian (Typewriter)"},
{0xF013, 5040, L"Slovak (QWERTY)"},
{0xF021, 5080, L"Thai Pattachote"},
{0xF014, 5059, L"Turkish F"},
{0xF015, 5044, L"Latvian (QWERTY)"},
{0xF027, 5088, L"Lithuanian"},
{0xF025, 5121, L"Armenian Western"},
{0xF0BD, 5234, L"Azerbaijani (Standard)"},
{0xF09F, 5164, L"Sorbian Extended"},
{0xF0A4, 5174, L"Macedonian (FYROM) - Standard"},
{0xF0AB, 5182, L"Georgian (QWERTY)"},
{0xF00C, 5105, L"Hindi Traditional"},
{0xF02B, 5141, L"Maltese 48-Key"},
{0xF02C, 5143, L"Sami Extended Norway"},
{0xF0BC, 5233, L"Tatar"},
{0xF02A, 5136, L"Bengali - INSCRIPT (Legacy)"},
{0xF0B5, 5222, L"Tibetan (PRC) - Updated"},
{0xF02F, 5200, L"Khmer (NIDA)"},
{0xF00E, 5131, L"Syriac Phonetic"},
{0xF0A0, 5167, L"Sinhala - Wij 9"},
{0xF037, 5201, L"Cherokee Nation Phonetic"},
{0xF0A7, 5171, L"Inuktitut - Naqittaut"},
{0xF00D, 5133, L"Divehi Typewriter"},
{0xF0AD, 5185, L"Uyghur"},
{0xF01E, 5089, L"Belgian (Comma)"},
{0xF02D, 5137, L"Finnish with Sami"},
{0xF0B2, 5225, L"Traditional Mongolian (Standard)"},
{0xF030, 5249, L"Myanmar (Phonetic order)"},
{0xF020, 5110, L"Canadian Multilingual Standard"},
{0xF036, 5208, L"Tifinagh (Full)"},
{0xF026, 5125, L"Gaelic"},
{0xF029, 5086, L"Arabic (102) AZERTY"},
{0xF0A3, 5173, L"Bulgarian (Phonetic)"},
{0xF00A, 5087, L"Czech Programmers"},
{0xF018, 5049, L"Greek (319)"},
{0xF001, 5026, L"United States-International"},
{0xF03D, 5214, L"Hebrew (Standard)"},
{0xF0A6, 5176, L"Romanian (Programmers)"},
{0xF033, 5203, L"Russian - Mnemonic"},
{0xF022, 5081, L"Thai Kedmanee (non-ShiftLock)"},
{0xF0A8, 5179, L"Ukrainian (Enhanced)"},
{0xF0B1, 5224, L"Latvian (Standard)"},
{0xF0A1, 5172, L"Lithuanian Standard"},
{0xF038, 5217, L"Armenian Phonetic"},
{0xF0AE, 5184, L"Sorbian Standard"},
{0xF0AC, 5181, L"Georgian (Ergonomic)"},
{0xF0A9, 5178, L"Bengali - INSCRIPT"},
{0xF0C8, 5246, L"Tamil 99"},
{0xF02E, 5142, L"Sami Extended Finland-Sweden"},
{0xF031, 5204, L"New Tai Lue"},
{0xF0AA, 5180, L"Bulgarian"},
{0xF017, 5050, L"Greek (220) Latin"},
{0xF01A, 5027, L"United States-Dvorak for left hand"},
{0xF023, 5082, L"Thai Pattachote (non-ShiftLock)"},
{0xF039, 5218, L"Armenian Typewriter"},
{0xF03B, 5215, L"Georgian Ministry of Education and Science Schools"},
{0xF034, 5205, L"Tai Le"},
{0xF0AF, 5195, L"Bulgarian (Phonetic Traditional)"},
{0xF011, 5051, L"Greek (319) Latin"},
{0xF01B, 5028, L"United States-Dvorak for right hand"},
{0xF03C, 5216, L"Georgian (Old Alphabets)"},
{0xF032, 5206, L"Ogham"},
{0xF019, 5047, L"Greek Latin"},
{0xF00B, 5123, L"US English Table for IBM Arabic 238_L"},
{0xF03A, 5213, L"Persian (Standard)"},
{0xF01F, 5122, L"Greek Polytonic"},
{0xF03E, 5210, L"Lisu (Basic)"},
{0xF03F, 5211, L"Lisu (Standard)"},
{0xF040, 5212, L"N’Ko"},
{0xF041, 5219, L"Phags-pa"},
{0xF0B3, 5220, L"Buginese"},
{0xF0B4, 5221, L"Gothic"},
{0xF0B6, 5223, L"Ol Chiki"},
{0xF0B7, 5226, L"Osmanya"},
{0xF0B8, 5227, L"Old Italic"},
{0xF0B9, 5228, L"Sora"},
{0xF0BA, 5230, L"Javanese"},
{0xF0BB, 5232, L"Futhark"},
{0xF0CB, 5250, L"Myanmar (Visual Order)"},
{0xF0CC, 5251, L"ADLaM"},
{0xF0CD, 5252, L"Osage"}
};
CString GetLayoutKeyboardDisplayName(DWORD layout, bool fLocalized = true) {
DWORD layout_id = layout >> 16;
CString keyboard_name = L"";
int number_of_elements = sizeof(LAYOUT_KEYBOARDS)/sizeof(LAYOUT_KEYBOARDS[0]);
for (int i = 0; i < number_of_elements; i++)
if (LAYOUT_KEYBOARDS[i].layout_id == layout_id) {
wchar_t szBuf[512];
if (fLocalized && SHLoadIndirectString(L"@%SystemRoot%\system32\input.dll,-" + IntToStr(LAYOUT_KEYBOARDS[i].display_name_id), szBuf, 512, NULL) == S_OK)
keyboard_name.Format(L"%s", szBuf);
else
keyboard_name = LAYOUT_KEYBOARDS[i].default_keyboard_name;
memset(szBuf, 0, 512);
return keyboard_name;
}
keyboard_name.Format(L"%X", layout_id);
keyboard_name.TrimLeft(L"0");
return keyboard_name;
}
//...
wprintf(L"%X, %s\n", (UINT)lpList[i], GetLayoutKeyboardDisplayName((UINT)lpList[i]));
键盘布局可以从 windows 注册表中获得。
以下是 python 代码:
# -*- coding: utf-8 -*-
# 从注册表中获取所有的键盘布局
# get all keyboard layouts from win regedit
import json
import winreg
def get_keyboard_layouts():
"""
windows 从注册表中获取所有的键盘布局
参考:
"""
print('get keyboard layouts')
# reg root path
loc_root = winreg.HKEY_LOCAL_MACHINE
# Keyboard Layouts reg path
loc_keyboards = r'SYSTEM\CurrentControlSet\Control\Keyboard Layouts'
# open reg path, get handle
handle_keyboards = winreg.OpenKey(key=loc_root, sub_key=loc_keyboards)
# get info of reg 'Keyboard Layouts'
# The result is a tuple of 3 items:
# An integer that identifies the number of sub keys this key has.
# An integer that identifies the number of values this key has.
# An integer that identifies when the key was last modified (if available)
# as 100's of nanoseconds since Jan 1, 1600.
info_keyboards = winreg.QueryInfoKey(handle_keyboards)
# get sub key length
keyboards_len = info_keyboards[0]
keyboard_layout = {}
# traverse to get sub key
for i in range(keyboards_len):
# sub key name
name_keyboard = winreg.EnumKey(handle_keyboards, i)
# sub key path
loc_keyboard = fr'{loc_keyboards}\{name_keyboard}'
# open sub key
handle_keyboard = winreg.OpenKey(key=loc_root, sub_key=loc_keyboard)
# get layout text
layout_text = winreg.QueryValueEx(handle_keyboard, 'Layout Text')[0]
# save layout name and layout text
keyboard_layout[name_keyboard] = layout_text
# 转换关系参考
# to hex string
# {'00000401': 'Arabic (101)', '00000402': 'Bulgarian (Typewriter)'}
# 得到的是 16 进制的字符串, 要转换为 0x804 的 16进制数
# 16 进制字符串转 16 进制整数
# int(win32api.GetKeyboardLayoutName(), 10) > 804
# 16 进制字符串转 10 进制整数
# int(win32api.GetKeyboardLayoutName(), 16) > 2052
name_keyboard_hex = hex(int(name_keyboard, 16))
# save hex layout name and layout text
keyboard_layout[name_keyboard_hex] = layout_text
handle_keyboard.Close()
handle_keyboards.Close()
return keyboard_layout
if __name__ == '__main__':
print(json.dumps(get_keyboard_layouts()))
keyboard_layouts = {
"00000401": "Arabic (101)",
"0x401": "Arabic (101)",
"00000402": "Bulgarian (Typewriter)",
"0x402": "Bulgarian (Typewriter)",
"00000404": "Chinese (Traditional) - US Keyboard",
"0x404": "Chinese (Traditional) - US Keyboard",
"00000405": "Czech",
"0x405": "Czech",
"00000406": "Danish",
"0x406": "Danish",
"00000407": "German",
"0x407": "German",
"00000408": "Greek",
"0x408": "Greek",
"00000409": "US",
"0x409": "US",
"0000040a": "Spanish",
"0x40a": "Spanish",
"0000040b": "Finnish",
"0x40b": "Finnish",
"0000040c": "French",
"0x40c": "French",
"0000040d": "Hebrew",
"0x40d": "Hebrew",
"0000040e": "Hungarian",
"0x40e": "Hungarian",
"0000040f": "Icelandic",
"0x40f": "Icelandic",
"00000410": "Italian",
"0x410": "Italian",
"00000411": "Japanese",
"0x411": "Japanese",
"00000412": "Korean",
"0x412": "Korean",
"00000413": "Dutch",
"0x413": "Dutch",
"00000414": "Norwegian",
"0x414": "Norwegian",
"00000415": "Polish (Programmers)",
"0x415": "Polish (Programmers)",
"00000416": "Portuguese (Brazilian ABNT)",
"0x416": "Portuguese (Brazilian ABNT)",
"00000418": "Romanian (Legacy)",
"0x418": "Romanian (Legacy)",
"00000419": "Russian",
"0x419": "Russian",
"0000041a": "Standard",
"0x41a": "Standard",
"0000041b": "Slovak",
"0x41b": "Slovak",
"0000041c": "Albanian",
"0x41c": "Albanian",
"0000041d": "Swedish",
"0x41d": "Swedish",
"0000041e": "Thai Kedmanee",
"0x41e": "Thai Kedmanee",
"0000041f": "Turkish Q",
"0x41f": "Turkish Q",
"00000420": "Urdu",
"0x420": "Urdu",
"00000422": "Ukrainian",
"0x422": "Ukrainian",
"00000423": "Belarusian",
"0x423": "Belarusian",
"00000424": "Slovenian",
"0x424": "Slovenian",
"00000425": "Estonian",
"0x425": "Estonian",
"00000426": "Latvian",
"0x426": "Latvian",
"00000427": "Lithuanian IBM",
"0x427": "Lithuanian IBM",
"00000428": "Tajik",
"0x428": "Tajik",
"00000429": "Persian",
"0x429": "Persian",
"0000042a": "Vietnamese",
"0x42a": "Vietnamese",
"0000042b": "Armenian Eastern",
"0x42b": "Armenian Eastern",
"0000042c": "Azeri Latin",
"0x42c": "Azeri Latin",
"0000042e": "Sorbian Standard (Legacy)",
"0x42e": "Sorbian Standard (Legacy)",
"0000042f": "Macedonian (FYROM)",
"0x42f": "Macedonian (FYROM)",
"00000432": "Setswana",
"0x432": "Setswana",
"00000437": "Georgian",
"0x437": "Georgian",
"00000438": "Faeroese",
"0x438": "Faeroese",
"00000439": "Devanagari - INSCRIPT",
"0x439": "Devanagari - INSCRIPT",
"0000043a": "Maltese 47-Key",
"0x43a": "Maltese 47-Key",
"0000043b": "Norwegian with Sami",
"0x43b": "Norwegian with Sami",
"0000043f": "Kazakh",
"0x43f": "Kazakh",
"00000440": "Kyrgyz Cyrillic",
"0x440": "Kyrgyz Cyrillic",
"00000442": "Turkmen",
"0x442": "Turkmen",
"00000444": "Tatar (Legacy)",
"0x444": "Tatar (Legacy)",
"00000445": "Bengali",
"0x445": "Bengali",
"00000446": "Punjabi",
"0x446": "Punjabi",
"00000447": "Gujarati",
"0x447": "Gujarati",
"00000448": "Oriya",
"0x448": "Oriya",
"00000449": "Tamil",
"0x449": "Tamil",
"0000044a": "Telugu",
"0x44a": "Telugu",
"0000044b": "Kannada",
"0x44b": "Kannada",
"0000044c": "Malayalam",
"0x44c": "Malayalam",
"0000044d": "Assamese - INSCRIPT",
"0x44d": "Assamese - INSCRIPT",
"0000044e": "Marathi",
"0x44e": "Marathi",
"00000450": "Mongolian Cyrillic",
"0x450": "Mongolian Cyrillic",
"00000451": "Tibetan (PRC)",
"0x451": "Tibetan (PRC)",
"00000452": "United Kingdom Extended",
"0x452": "United Kingdom Extended",
"00000453": "Khmer",
"0x453": "Khmer",
"00000454": "Lao",
"0x454": "Lao",
"0000045a": "Syriac",
"0x45a": "Syriac",
"0000045b": "Sinhala",
"0x45b": "Sinhala",
"0000045c": "Cherokee Nation",
"0x45c": "Cherokee Nation",
"00000461": "Nepali",
"0x461": "Nepali",
"00000463": "Pashto (Afghanistan)",
"0x463": "Pashto (Afghanistan)",
"00000465": "Divehi Phonetic",
"0x465": "Divehi Phonetic",
"00000468": "Hausa",
"0x468": "Hausa",
"0000046a": "Yoruba",
"0x46a": "Yoruba",
"0000046c": "Sesotho sa Leboa",
"0x46c": "Sesotho sa Leboa",
"0000046d": "Bashkir",
"0x46d": "Bashkir",
"0000046e": "Luxembourgish",
"0x46e": "Luxembourgish",
"0000046f": "Greenlandic",
"0x46f": "Greenlandic",
"00000470": "Igbo",
"0x470": "Igbo",
"00000474": "Guarani",
"0x474": "Guarani",
"00000475": "Hawaiian",
"0x475": "Hawaiian",
"00000480": "Uyghur (Legacy)",
"0x480": "Uyghur (Legacy)",
"00000481": "Maori",
"0x481": "Maori",
"00000485": "Sakha",
"0x485": "Sakha",
"00000488": "Wolof",
"0x488": "Wolof",
"00000492": "Central Kurdish",
"0x492": "Central Kurdish",
"00000804": "Chinese (Simplified) - US Keyboard",
"0x804": "Chinese (Simplified) - US Keyboard",
"00000807": "Swiss German",
"0x807": "Swiss German",
"00000809": "United Kingdom",
"0x809": "United Kingdom",
"0000080a": "Latin American",
"0x80a": "Latin American",
"0000080c": "Belgian French",
"0x80c": "Belgian French",
"00000813": "Belgian (Period)",
"0x813": "Belgian (Period)",
"00000816": "Portuguese",
"0x816": "Portuguese",
"0000081a": "Serbian (Latin)",
"0x81a": "Serbian (Latin)",
"0000082c": "Azeri Cyrillic",
"0x82c": "Azeri Cyrillic",
"0000083b": "Swedish with Sami",
"0x83b": "Swedish with Sami",
"00000843": "Uzbek Cyrillic",
"0x843": "Uzbek Cyrillic",
"00000850": "Mongolian (Mongolian Script)",
"0x850": "Mongolian (Mongolian Script)",
"0000085d": "Inuktitut - Latin",
"0x85d": "Inuktitut - Latin",
"0000085f": "Central Atlas Tamazight",
"0x85f": "Central Atlas Tamazight",
"00000c04": "Chinese (Traditional, Hong Kong S.A.R.) - US Keyboard",
"0xc04": "Chinese (Traditional, Hong Kong S.A.R.) - US Keyboard",
"00000c0c": "Canadian French (Legacy)",
"0xc0c": "Canadian French (Legacy)",
"00000c1a": "Serbian (Cyrillic)",
"0xc1a": "Serbian (Cyrillic)",
"00000C51": "Dzongkha",
"0xc51": "Dzongkha",
"00001004": "Chinese (Simplified, Singapore) - US Keyboard",
"0x1004": "Chinese (Simplified, Singapore) - US Keyboard",
"00001009": "Canadian French",
"0x1009": "Canadian French",
"0000100c": "Swiss French",
"0x100c": "Swiss French",
"0000105f": "Tifinagh (Basic)",
"0x105f": "Tifinagh (Basic)",
"00001404": "Chinese (Traditional, Macao S.A.R.) - US Keyboard",
"0x1404": "Chinese (Traditional, Macao S.A.R.) - US Keyboard",
"00001809": "Irish",
"0x1809": "Irish",
"0000201a": "Bosnian (Cyrillic)",
"0x201a": "Bosnian (Cyrillic)",
"00004009": "India",
"0x4009": "India",
"00010401": "Arabic (102)",
"0x10401": "Arabic (102)",
"00010402": "Bulgarian (Latin)",
"0x10402": "Bulgarian (Latin)",
"00010405": "Czech (QWERTY)",
"0x10405": "Czech (QWERTY)",
"00010407": "German (IBM)",
"0x10407": "German (IBM)",
"00010408": "Greek (220)",
"0x10408": "Greek (220)",
"00010409": "United States-Dvorak",
"0x10409": "United States-Dvorak",
"0001040a": "Spanish Variation",
"0x1040a": "Spanish Variation",
"0001040e": "Hungarian 101-key",
"0x1040e": "Hungarian 101-key",
"00010410": "Italian (142)",
"0x10410": "Italian (142)",
"00010415": "Polish (214)",
"0x10415": "Polish (214)",
"00010416": "Portuguese (Brazilian ABNT2)",
"0x10416": "Portuguese (Brazilian ABNT2)",
"00010418": "Romanian (Standard)",
"0x10418": "Romanian (Standard)",
"00010419": "Russian (Typewriter)",
"0x10419": "Russian (Typewriter)",
"0001041b": "Slovak (QWERTY)",
"0x1041b": "Slovak (QWERTY)",
"0001041e": "Thai Pattachote",
"0x1041e": "Thai Pattachote",
"0001041f": "Turkish F",
"0x1041f": "Turkish F",
"00010426": "Latvian (QWERTY)",
"0x10426": "Latvian (QWERTY)",
"00010427": "Lithuanian",
"0x10427": "Lithuanian",
"0001042b": "Armenian Western",
"0x1042b": "Armenian Western",
"0001042c": "Azerbaijani (Standard)",
"0x1042c": "Azerbaijani (Standard)",
"0001042e": "Sorbian Extended",
"0x1042e": "Sorbian Extended",
"0001042f": "Macedonian (FYROM) - Standard",
"0x1042f": "Macedonian (FYROM) - Standard",
"00010437": "Georgian (QWERTY)",
"0x10437": "Georgian (QWERTY)",
"00010439": "Hindi Traditional",
"0x10439": "Hindi Traditional",
"0001043a": "Maltese 48-Key",
"0x1043a": "Maltese 48-Key",
"0001043b": "Sami Extended Norway",
"0x1043b": "Sami Extended Norway",
"00010444": "Tatar",
"0x10444": "Tatar",
"00010445": "Bengali - INSCRIPT (Legacy)",
"0x10445": "Bengali - INSCRIPT (Legacy)",
"00010451": "Tibetan (PRC) - Updated",
"0x10451": "Tibetan (PRC) - Updated",
"00010453": "Khmer (NIDA)",
"0x10453": "Khmer (NIDA)",
"0001045a": "Syriac Phonetic",
"0x1045a": "Syriac Phonetic",
"0001045b": "Sinhala - Wij 9",
"0x1045b": "Sinhala - Wij 9",
"0001045c": "Cherokee Nation Phonetic",
"0x1045c": "Cherokee Nation Phonetic",
"0001045d": "Inuktitut - Naqittaut",
"0x1045d": "Inuktitut - Naqittaut",
"00010465": "Divehi Typewriter",
"0x10465": "Divehi Typewriter",
"00010480": "Uyghur",
"0x10480": "Uyghur",
"0001080c": "Belgian (Comma)",
"0x1080c": "Belgian (Comma)",
"0001083b": "Finnish with Sami",
"0x1083b": "Finnish with Sami",
"00010850": "Traditional Mongolian (Standard)",
"0x10850": "Traditional Mongolian (Standard)",
"00010c00": "Myanmar (Phonetic order)",
"0x10c00": "Myanmar (Phonetic order)",
"00011009": "Canadian Multilingual Standard",
"0x11009": "Canadian Multilingual Standard",
"0001105f": "Tifinagh (Full)",
"0x1105f": "Tifinagh (Full)",
"00011809": "Gaelic",
"0x11809": "Gaelic",
"00020401": "Arabic (102) AZERTY",
"0x20401": "Arabic (102) AZERTY",
"00020402": "Bulgarian (Phonetic)",
"0x20402": "Bulgarian (Phonetic)",
"00020405": "Czech Programmers",
"0x20405": "Czech Programmers",
"00020408": "Greek (319)",
"0x20408": "Greek (319)",
"00020409": "United States-International",
"0x20409": "United States-International",
"0002040d": "Hebrew (Standard)",
"0x2040d": "Hebrew (Standard)",
"00020418": "Romanian (Programmers)",
"0x20418": "Romanian (Programmers)",
"00020419": "Russian - Mnemonic",
"0x20419": "Russian - Mnemonic",
"0002041e": "Thai Kedmanee (non-ShiftLock)",
"0x2041e": "Thai Kedmanee (non-ShiftLock)",
"00020422": "Ukrainian (Enhanced)",
"0x20422": "Ukrainian (Enhanced)",
"00020426": "Latvian (Standard)",
"0x20426": "Latvian (Standard)",
"00020427": "Lithuanian Standard",
"0x20427": "Lithuanian Standard",
"0002042b": "Armenian Phonetic",
"0x2042b": "Armenian Phonetic",
"0002042e": "Sorbian Standard",
"0x2042e": "Sorbian Standard",
"00020437": "Georgian (Ergonomic)",
"0x20437": "Georgian (Ergonomic)",
"00020445": "Bengali - INSCRIPT",
"0x20445": "Bengali - INSCRIPT",
"00020449": "Tamil 99",
"0x20449": "Tamil 99",
"0002083b": "Sami Extended Finland-Sweden",
"0x2083b": "Sami Extended Finland-Sweden",
"00020c00": "New Tai Lue",
"0x20c00": "New Tai Lue",
"00030402": "Bulgarian",
"0x30402": "Bulgarian",
"00030408": "Greek (220) Latin",
"0x30408": "Greek (220) Latin",
"00030409": "United States-Dvorak for left hand",
"0x30409": "United States-Dvorak for left hand",
"0003041e": "Thai Pattachote (non-ShiftLock)",
"0x3041e": "Thai Pattachote (non-ShiftLock)",
"0003042b": "Armenian Typewriter",
"0x3042b": "Armenian Typewriter",
"00030437": "Georgian Ministry of Education and Science Schools",
"0x30437": "Georgian Ministry of Education and Science Schools",
"00030c00": "Tai Le",
"0x30c00": "Tai Le",
"00040402": "Bulgarian (Phonetic Traditional)",
"0x40402": "Bulgarian (Phonetic Traditional)",
"00040408": "Greek (319) Latin",
"0x40408": "Greek (319) Latin",
"00040409": "United States-Dvorak for right hand",
"0x40409": "United States-Dvorak for right hand",
"00040437": "Georgian (Old Alphabets)",
"0x40437": "Georgian (Old Alphabets)",
"00040c00": "Ogham",
"0x40c00": "Ogham",
"00050408": "Greek Latin",
"0x50408": "Greek Latin",
"00050409": "US English Table for IBM Arabic 238_L",
"0x50409": "US English Table for IBM Arabic 238_L",
"00050429": "Persian (Standard)",
"0x50429": "Persian (Standard)",
"00060408": "Greek Polytonic",
"0x60408": "Greek Polytonic",
"00070c00": "Lisu (Basic)",
"0x70c00": "Lisu (Basic)",
"00080c00": "Lisu (Standard)",
"0x80c00": "Lisu (Standard)",
"00090c00": "N\u2019Ko",
"0x90c00": "N\u2019Ko",
"000a0c00": "Phags-pa",
"0xa0c00": "Phags-pa",
"000b0c00": "Buginese",
"0xb0c00": "Buginese",
"000c0c00": "Gothic",
"0xc0c00": "Gothic",
"000d0c00": "Ol Chiki",
"0xd0c00": "Ol Chiki",
"000e0c00": "Osmanya",
"0xe0c00": "Osmanya",
"000f0c00": "Old Italic",
"0xf0c00": "Old Italic",
"00100c00": "Sora",
"0x100c00": "Sora",
"00110c00": "Javanese",
"0x110c00": "Javanese",
"00120c00": "Futhark",
"0x120c00": "Futhark",
"00130c00": "Myanmar (Visual Order)",
"0x130c00": "Myanmar (Visual Order)",
"00140c00": "ADLaM",
"0x140c00": "ADLaM",
"00150c00": "Osage",
"0x150c00": "Osage"
}
例如,我安装了 2 种语言 — 英语和俄语。俄语有 2 个键盘——普通和助记键:
当我运行代码:
UINT uLayouts;
HKL *lpList = NULL;
wchar_t szBufLng[512], szBufCtry[512];
uLayouts = GetKeyboardLayoutList(0, NULL);
lpList = (HKL*)LocalAlloc(LPTR, (uLayouts * sizeof(HKL)));
uLayouts = GetKeyboardLayoutList(uLayouts, lpList);
for(int i = 0; i < uLayouts; ++i)
{
GetLocaleInfo(MAKELCID(((UINT)lpList[i] & 0xffffffff),
SORT_DEFAULT), LOCALE_SISO639LANGNAME, szBufLng, 512);
GetLocaleInfo(MAKELCID(((UINT)lpList[i] & 0xffffffff),
SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, szBufCtry, 512);
wprintf(L"%s-%s, %x\n", szBufLng, szBufCtry, (UINT)lpList[i]);
memset(szBufLng, 0, 512);
memset(szBufCtry, 0, 512);
}
if(lpList)
LocalFree(lpList);
我得到以下结果:
en-US, 04090409
ru-RU, 04190419
ru-RU, f0330419
我的问题是如何区分助记词? 至少要显示这样的内容:
en-US, 04090409
ru-RU, 04190419
rum-RU, f0330419
如何获取键盘名称?
同样的问题在这里讨论(无解): https://forums.codeguru.com/showthread.php?492287-Keyboard-Layout-Name
我在 Windows 10 中从注册表(\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard 布局)导出数据,并基于它创建了一个 table。并借助 SHLoadIndirectString 获得了键盘的本地化名称。
struct LAYOUT_KEYBOARD_INFO {
LCID layout_id;
short display_name_id;
wchar_t default_keyboard_name[64];
};
LAYOUT_KEYBOARD_INFO LAYOUT_KEYBOARDS[] = {
{0x0401, 5084, L"Arabic (101)"},
{0x0402, 5053, L"Bulgarian (Typewriter)"},
{0x0404, 5065, L"Chinese (Traditional) - US Keyboard"},
{0x0405, 5031, L"Czech"},
{0x0406, 5007, L"Danish"},
{0x0407, 5011, L"German"},
{0x0408, 5046, L"Greek"},
{0x0409, 5000, L"US"},
{0x040A, 5020, L"Spanish"},
{0x040B, 5009, L"Finnish"},
{0x040C, 5010, L"French"},
{0x040D, 5083, L"Hebrew"},
{0x040E, 5033, L"Hungarian"},
{0x040F, 5013, L"Icelandic"},
{0x0410, 5015, L"Italian"},
{0x0411, 5061, L"Japanese"},
{0x0412, 5063, L"Korean"},
{0x0413, 5008, L"Dutch"},
{0x0414, 5018, L"Norwegian"},
{0x0415, 5035, L"Polish (Programmers)"},
{0x0416, 5003, L"Portuguese (Brazilian ABNT)"},
{0x0418, 5037, L"Romanian (Legacy)"},
{0x0419, 5055, L"Russian"},
{0x041A, 5030, L"Standard"},
{0x041B, 5039, L"Slovak"},
{0x041C, 5029, L"Albanian"},
{0x041D, 5022, L"Swedish"},
{0x041E, 5079, L"Thai Kedmanee"},
{0x041F, 5060, L"Turkish Q"},
{0x0420, 5129, L"Urdu"},
{0x0422, 5058, L"Ukrainian"},
{0x0423, 5052, L"Belarusian"},
{0x0424, 5041, L"Slovenian"},
{0x0425, 5042, L"Estonian"},
{0x0426, 5043, L"Latvian"},
{0x0427, 5045, L"Lithuanian IBM"},
{0x0428, 5151, L"Tajik"},
{0x0429, 5124, L"Persian"},
{0x042A, 5118, L"Vietnamese"},
{0x042B, 5120, L"Armenian Eastern"},
{0x042C, 5117, L"Azeri Latin"},
{0x042E, 5163, L"Sorbian Standard (Legacy)"},
{0x042F, 5109, L"Macedonian (FYROM)"},
{0x0432, 5191, L"Setswana"},
{0x0437, 5119, L"Georgian"},
{0x0438, 5108, L"Faeroese"},
{0x0439, 5096, L"Devanagari - INSCRIPT"},
{0x043A, 5140, L"Maltese 47-Key"},
{0x043B, 5138, L"Norwegian with Sami"},
{0x043F, 5113, L"Kazakh"},
{0x0440, 5128, L"Kyrgyz Cyrillic"},
{0x0442, 5150, L"Turkmen"},
{0x0444, 5116, L"Tatar (Legacy)"},
{0x0445, 5135, L"Bengali"},
{0x0446, 5101, L"Punjabi"},
{0x0447, 5097, L"Gujarati"},
{0x0448, 5100, L"Oriya"},
{0x0449, 5102, L"Tamil"},
{0x044A, 5103, L"Telugu"},
{0x044B, 5098, L"Kannada"},
{0x044C, 5139, L"Malayalam"},
{0x044D, 5177, L"Assamese - INSCRIPT"},
{0x044E, 5104, L"Marathi"},
{0x0450, 5127, L"Mongolian Cyrillic"},
{0x0451, 5154, L"Tibetan (PRC)"},
{0x0452, 5145, L"United Kingdom Extended"},
{0x0453, 5161, L"Khmer"},
{0x0454, 5162, L"Lao"},
{0x045A, 5130, L"Syriac"},
{0x045B, 5166, L"Sinhala"},
{0x045C, 5209, L"Cherokee Nation"},
{0x0461, 5169, L"Nepali"},
{0x0463, 5159, L"Pashto (Afghanistan)"},
{0x0465, 5132, L"Divehi Phonetic"},
{0x0468, 5187, L"Hausa"},
{0x046A, 5189, L"Yoruba"},
{0x046C, 5186, L"Sesotho sa Leboa"},
{0x046D, 5148, L"Bashkir"},
{0x046E, 5168, L"Luxembourgish"},
{0x046F, 5170, L"Greenlandic"},
{0x0470, 5188, L"Igbo"},
{0x0474, 5231, L"Guarani"},
{0x0475, 5198, L"Hawaiian"},
{0x0480, 5165, L"Uyghur (Legacy)"},
{0x0481, 5146, L"Maori"},
{0x0485, 5160, L"Sakha"},
{0x0488, 5190, L"Wolof"},
{0x0492, 5199, L"Central Kurdish"},
{0x0804, 5072, L"Chinese (Simplified) - US Keyboard"},
{0x0807, 5024, L"Swiss German"},
{0x0809, 5025, L"United Kingdom"},
{0x080A, 5017, L"Latin American"},
{0x080C, 5002, L"Belgian French"},
{0x0813, 5001, L"Belgian (Period)"},
{0x0816, 5019, L"Portuguese"},
{0x081A, 5038, L"Serbian (Latin)"},
{0x082C, 5115, L"Azeri Cyrillic"},
{0x083B, 5144, L"Swedish with Sami"},
{0x0843, 5114, L"Uzbek Cyrillic"},
{0x0850, 5158, L"Mongolian (Mongolian Script)"},
{0x085D, 5156, L"Inuktitut - Latin"},
{0x085F, 5229, L"Central Atlas Tamazight"},
{0x0C04, 5192, L"Chinese (Traditional, Hong Kong S.A.R.) - US Keyboard"},
{0x0C0C, 5005, L"Canadian French (Legacy)"},
{0x0C1A, 5057, L"Serbian (Cyrillic)"},
{0x0C51, 5235, L"Dzongkha"},
{0x1004, 5193, L"Chinese (Simplified, Singapore) - US Keyboard"},
{0x1009, 5004, L"Canadian French"},
{0x100C, 5023, L"Swiss French"},
{0x105F, 5207, L"Tifinagh (Basic)"},
{0x1404, 5194, L"Chinese (Traditional, Macao S.A.R.) - US Keyboard"},
{0x1809, 5014, L"Irish"},
{0x201A, 5155, L"Bosnian (Cyrillic)"},
{0x4009, 5196, L"India"},
// Added F to "Layout Id"
{0xF028, 5085, L"Arabic (102)"},
{0xF004, 5054, L"Bulgarian (Latin)"},
{0xF005, 5032, L"Czech (QWERTY)"},
{0xF012, 5012, L"German (IBM)"},
{0xF016, 5048, L"Greek (220)"},
{0xF002, 5092, L"United States-Dvorak"},
{0xF086, 5021, L"Spanish Variation"},
{0xF006, 5034, L"Hungarian 101-key"},
{0xF003, 5016, L"Italian (142)"},
{0xF007, 5036, L"Polish (214)"},
{0xF010, 5126, L"Portuguese (Brazilian ABNT2)"},
{0xF0A5, 5175, L"Romanian (Standard)"},
{0xF008, 5056, L"Russian (Typewriter)"},
{0xF013, 5040, L"Slovak (QWERTY)"},
{0xF021, 5080, L"Thai Pattachote"},
{0xF014, 5059, L"Turkish F"},
{0xF015, 5044, L"Latvian (QWERTY)"},
{0xF027, 5088, L"Lithuanian"},
{0xF025, 5121, L"Armenian Western"},
{0xF0BD, 5234, L"Azerbaijani (Standard)"},
{0xF09F, 5164, L"Sorbian Extended"},
{0xF0A4, 5174, L"Macedonian (FYROM) - Standard"},
{0xF0AB, 5182, L"Georgian (QWERTY)"},
{0xF00C, 5105, L"Hindi Traditional"},
{0xF02B, 5141, L"Maltese 48-Key"},
{0xF02C, 5143, L"Sami Extended Norway"},
{0xF0BC, 5233, L"Tatar"},
{0xF02A, 5136, L"Bengali - INSCRIPT (Legacy)"},
{0xF0B5, 5222, L"Tibetan (PRC) - Updated"},
{0xF02F, 5200, L"Khmer (NIDA)"},
{0xF00E, 5131, L"Syriac Phonetic"},
{0xF0A0, 5167, L"Sinhala - Wij 9"},
{0xF037, 5201, L"Cherokee Nation Phonetic"},
{0xF0A7, 5171, L"Inuktitut - Naqittaut"},
{0xF00D, 5133, L"Divehi Typewriter"},
{0xF0AD, 5185, L"Uyghur"},
{0xF01E, 5089, L"Belgian (Comma)"},
{0xF02D, 5137, L"Finnish with Sami"},
{0xF0B2, 5225, L"Traditional Mongolian (Standard)"},
{0xF030, 5249, L"Myanmar (Phonetic order)"},
{0xF020, 5110, L"Canadian Multilingual Standard"},
{0xF036, 5208, L"Tifinagh (Full)"},
{0xF026, 5125, L"Gaelic"},
{0xF029, 5086, L"Arabic (102) AZERTY"},
{0xF0A3, 5173, L"Bulgarian (Phonetic)"},
{0xF00A, 5087, L"Czech Programmers"},
{0xF018, 5049, L"Greek (319)"},
{0xF001, 5026, L"United States-International"},
{0xF03D, 5214, L"Hebrew (Standard)"},
{0xF0A6, 5176, L"Romanian (Programmers)"},
{0xF033, 5203, L"Russian - Mnemonic"},
{0xF022, 5081, L"Thai Kedmanee (non-ShiftLock)"},
{0xF0A8, 5179, L"Ukrainian (Enhanced)"},
{0xF0B1, 5224, L"Latvian (Standard)"},
{0xF0A1, 5172, L"Lithuanian Standard"},
{0xF038, 5217, L"Armenian Phonetic"},
{0xF0AE, 5184, L"Sorbian Standard"},
{0xF0AC, 5181, L"Georgian (Ergonomic)"},
{0xF0A9, 5178, L"Bengali - INSCRIPT"},
{0xF0C8, 5246, L"Tamil 99"},
{0xF02E, 5142, L"Sami Extended Finland-Sweden"},
{0xF031, 5204, L"New Tai Lue"},
{0xF0AA, 5180, L"Bulgarian"},
{0xF017, 5050, L"Greek (220) Latin"},
{0xF01A, 5027, L"United States-Dvorak for left hand"},
{0xF023, 5082, L"Thai Pattachote (non-ShiftLock)"},
{0xF039, 5218, L"Armenian Typewriter"},
{0xF03B, 5215, L"Georgian Ministry of Education and Science Schools"},
{0xF034, 5205, L"Tai Le"},
{0xF0AF, 5195, L"Bulgarian (Phonetic Traditional)"},
{0xF011, 5051, L"Greek (319) Latin"},
{0xF01B, 5028, L"United States-Dvorak for right hand"},
{0xF03C, 5216, L"Georgian (Old Alphabets)"},
{0xF032, 5206, L"Ogham"},
{0xF019, 5047, L"Greek Latin"},
{0xF00B, 5123, L"US English Table for IBM Arabic 238_L"},
{0xF03A, 5213, L"Persian (Standard)"},
{0xF01F, 5122, L"Greek Polytonic"},
{0xF03E, 5210, L"Lisu (Basic)"},
{0xF03F, 5211, L"Lisu (Standard)"},
{0xF040, 5212, L"N’Ko"},
{0xF041, 5219, L"Phags-pa"},
{0xF0B3, 5220, L"Buginese"},
{0xF0B4, 5221, L"Gothic"},
{0xF0B6, 5223, L"Ol Chiki"},
{0xF0B7, 5226, L"Osmanya"},
{0xF0B8, 5227, L"Old Italic"},
{0xF0B9, 5228, L"Sora"},
{0xF0BA, 5230, L"Javanese"},
{0xF0BB, 5232, L"Futhark"},
{0xF0CB, 5250, L"Myanmar (Visual Order)"},
{0xF0CC, 5251, L"ADLaM"},
{0xF0CD, 5252, L"Osage"}
};
CString GetLayoutKeyboardDisplayName(DWORD layout, bool fLocalized = true) {
DWORD layout_id = layout >> 16;
CString keyboard_name = L"";
int number_of_elements = sizeof(LAYOUT_KEYBOARDS)/sizeof(LAYOUT_KEYBOARDS[0]);
for (int i = 0; i < number_of_elements; i++)
if (LAYOUT_KEYBOARDS[i].layout_id == layout_id) {
wchar_t szBuf[512];
if (fLocalized && SHLoadIndirectString(L"@%SystemRoot%\system32\input.dll,-" + IntToStr(LAYOUT_KEYBOARDS[i].display_name_id), szBuf, 512, NULL) == S_OK)
keyboard_name.Format(L"%s", szBuf);
else
keyboard_name = LAYOUT_KEYBOARDS[i].default_keyboard_name;
memset(szBuf, 0, 512);
return keyboard_name;
}
keyboard_name.Format(L"%X", layout_id);
keyboard_name.TrimLeft(L"0");
return keyboard_name;
}
//...
wprintf(L"%X, %s\n", (UINT)lpList[i], GetLayoutKeyboardDisplayName((UINT)lpList[i]));
键盘布局可以从 windows 注册表中获得。 以下是 python 代码:
# -*- coding: utf-8 -*-
# 从注册表中获取所有的键盘布局
# get all keyboard layouts from win regedit
import json
import winreg
def get_keyboard_layouts():
"""
windows 从注册表中获取所有的键盘布局
参考:
"""
print('get keyboard layouts')
# reg root path
loc_root = winreg.HKEY_LOCAL_MACHINE
# Keyboard Layouts reg path
loc_keyboards = r'SYSTEM\CurrentControlSet\Control\Keyboard Layouts'
# open reg path, get handle
handle_keyboards = winreg.OpenKey(key=loc_root, sub_key=loc_keyboards)
# get info of reg 'Keyboard Layouts'
# The result is a tuple of 3 items:
# An integer that identifies the number of sub keys this key has.
# An integer that identifies the number of values this key has.
# An integer that identifies when the key was last modified (if available)
# as 100's of nanoseconds since Jan 1, 1600.
info_keyboards = winreg.QueryInfoKey(handle_keyboards)
# get sub key length
keyboards_len = info_keyboards[0]
keyboard_layout = {}
# traverse to get sub key
for i in range(keyboards_len):
# sub key name
name_keyboard = winreg.EnumKey(handle_keyboards, i)
# sub key path
loc_keyboard = fr'{loc_keyboards}\{name_keyboard}'
# open sub key
handle_keyboard = winreg.OpenKey(key=loc_root, sub_key=loc_keyboard)
# get layout text
layout_text = winreg.QueryValueEx(handle_keyboard, 'Layout Text')[0]
# save layout name and layout text
keyboard_layout[name_keyboard] = layout_text
# 转换关系参考
# to hex string
# {'00000401': 'Arabic (101)', '00000402': 'Bulgarian (Typewriter)'}
# 得到的是 16 进制的字符串, 要转换为 0x804 的 16进制数
# 16 进制字符串转 16 进制整数
# int(win32api.GetKeyboardLayoutName(), 10) > 804
# 16 进制字符串转 10 进制整数
# int(win32api.GetKeyboardLayoutName(), 16) > 2052
name_keyboard_hex = hex(int(name_keyboard, 16))
# save hex layout name and layout text
keyboard_layout[name_keyboard_hex] = layout_text
handle_keyboard.Close()
handle_keyboards.Close()
return keyboard_layout
if __name__ == '__main__':
print(json.dumps(get_keyboard_layouts()))
keyboard_layouts = {
"00000401": "Arabic (101)",
"0x401": "Arabic (101)",
"00000402": "Bulgarian (Typewriter)",
"0x402": "Bulgarian (Typewriter)",
"00000404": "Chinese (Traditional) - US Keyboard",
"0x404": "Chinese (Traditional) - US Keyboard",
"00000405": "Czech",
"0x405": "Czech",
"00000406": "Danish",
"0x406": "Danish",
"00000407": "German",
"0x407": "German",
"00000408": "Greek",
"0x408": "Greek",
"00000409": "US",
"0x409": "US",
"0000040a": "Spanish",
"0x40a": "Spanish",
"0000040b": "Finnish",
"0x40b": "Finnish",
"0000040c": "French",
"0x40c": "French",
"0000040d": "Hebrew",
"0x40d": "Hebrew",
"0000040e": "Hungarian",
"0x40e": "Hungarian",
"0000040f": "Icelandic",
"0x40f": "Icelandic",
"00000410": "Italian",
"0x410": "Italian",
"00000411": "Japanese",
"0x411": "Japanese",
"00000412": "Korean",
"0x412": "Korean",
"00000413": "Dutch",
"0x413": "Dutch",
"00000414": "Norwegian",
"0x414": "Norwegian",
"00000415": "Polish (Programmers)",
"0x415": "Polish (Programmers)",
"00000416": "Portuguese (Brazilian ABNT)",
"0x416": "Portuguese (Brazilian ABNT)",
"00000418": "Romanian (Legacy)",
"0x418": "Romanian (Legacy)",
"00000419": "Russian",
"0x419": "Russian",
"0000041a": "Standard",
"0x41a": "Standard",
"0000041b": "Slovak",
"0x41b": "Slovak",
"0000041c": "Albanian",
"0x41c": "Albanian",
"0000041d": "Swedish",
"0x41d": "Swedish",
"0000041e": "Thai Kedmanee",
"0x41e": "Thai Kedmanee",
"0000041f": "Turkish Q",
"0x41f": "Turkish Q",
"00000420": "Urdu",
"0x420": "Urdu",
"00000422": "Ukrainian",
"0x422": "Ukrainian",
"00000423": "Belarusian",
"0x423": "Belarusian",
"00000424": "Slovenian",
"0x424": "Slovenian",
"00000425": "Estonian",
"0x425": "Estonian",
"00000426": "Latvian",
"0x426": "Latvian",
"00000427": "Lithuanian IBM",
"0x427": "Lithuanian IBM",
"00000428": "Tajik",
"0x428": "Tajik",
"00000429": "Persian",
"0x429": "Persian",
"0000042a": "Vietnamese",
"0x42a": "Vietnamese",
"0000042b": "Armenian Eastern",
"0x42b": "Armenian Eastern",
"0000042c": "Azeri Latin",
"0x42c": "Azeri Latin",
"0000042e": "Sorbian Standard (Legacy)",
"0x42e": "Sorbian Standard (Legacy)",
"0000042f": "Macedonian (FYROM)",
"0x42f": "Macedonian (FYROM)",
"00000432": "Setswana",
"0x432": "Setswana",
"00000437": "Georgian",
"0x437": "Georgian",
"00000438": "Faeroese",
"0x438": "Faeroese",
"00000439": "Devanagari - INSCRIPT",
"0x439": "Devanagari - INSCRIPT",
"0000043a": "Maltese 47-Key",
"0x43a": "Maltese 47-Key",
"0000043b": "Norwegian with Sami",
"0x43b": "Norwegian with Sami",
"0000043f": "Kazakh",
"0x43f": "Kazakh",
"00000440": "Kyrgyz Cyrillic",
"0x440": "Kyrgyz Cyrillic",
"00000442": "Turkmen",
"0x442": "Turkmen",
"00000444": "Tatar (Legacy)",
"0x444": "Tatar (Legacy)",
"00000445": "Bengali",
"0x445": "Bengali",
"00000446": "Punjabi",
"0x446": "Punjabi",
"00000447": "Gujarati",
"0x447": "Gujarati",
"00000448": "Oriya",
"0x448": "Oriya",
"00000449": "Tamil",
"0x449": "Tamil",
"0000044a": "Telugu",
"0x44a": "Telugu",
"0000044b": "Kannada",
"0x44b": "Kannada",
"0000044c": "Malayalam",
"0x44c": "Malayalam",
"0000044d": "Assamese - INSCRIPT",
"0x44d": "Assamese - INSCRIPT",
"0000044e": "Marathi",
"0x44e": "Marathi",
"00000450": "Mongolian Cyrillic",
"0x450": "Mongolian Cyrillic",
"00000451": "Tibetan (PRC)",
"0x451": "Tibetan (PRC)",
"00000452": "United Kingdom Extended",
"0x452": "United Kingdom Extended",
"00000453": "Khmer",
"0x453": "Khmer",
"00000454": "Lao",
"0x454": "Lao",
"0000045a": "Syriac",
"0x45a": "Syriac",
"0000045b": "Sinhala",
"0x45b": "Sinhala",
"0000045c": "Cherokee Nation",
"0x45c": "Cherokee Nation",
"00000461": "Nepali",
"0x461": "Nepali",
"00000463": "Pashto (Afghanistan)",
"0x463": "Pashto (Afghanistan)",
"00000465": "Divehi Phonetic",
"0x465": "Divehi Phonetic",
"00000468": "Hausa",
"0x468": "Hausa",
"0000046a": "Yoruba",
"0x46a": "Yoruba",
"0000046c": "Sesotho sa Leboa",
"0x46c": "Sesotho sa Leboa",
"0000046d": "Bashkir",
"0x46d": "Bashkir",
"0000046e": "Luxembourgish",
"0x46e": "Luxembourgish",
"0000046f": "Greenlandic",
"0x46f": "Greenlandic",
"00000470": "Igbo",
"0x470": "Igbo",
"00000474": "Guarani",
"0x474": "Guarani",
"00000475": "Hawaiian",
"0x475": "Hawaiian",
"00000480": "Uyghur (Legacy)",
"0x480": "Uyghur (Legacy)",
"00000481": "Maori",
"0x481": "Maori",
"00000485": "Sakha",
"0x485": "Sakha",
"00000488": "Wolof",
"0x488": "Wolof",
"00000492": "Central Kurdish",
"0x492": "Central Kurdish",
"00000804": "Chinese (Simplified) - US Keyboard",
"0x804": "Chinese (Simplified) - US Keyboard",
"00000807": "Swiss German",
"0x807": "Swiss German",
"00000809": "United Kingdom",
"0x809": "United Kingdom",
"0000080a": "Latin American",
"0x80a": "Latin American",
"0000080c": "Belgian French",
"0x80c": "Belgian French",
"00000813": "Belgian (Period)",
"0x813": "Belgian (Period)",
"00000816": "Portuguese",
"0x816": "Portuguese",
"0000081a": "Serbian (Latin)",
"0x81a": "Serbian (Latin)",
"0000082c": "Azeri Cyrillic",
"0x82c": "Azeri Cyrillic",
"0000083b": "Swedish with Sami",
"0x83b": "Swedish with Sami",
"00000843": "Uzbek Cyrillic",
"0x843": "Uzbek Cyrillic",
"00000850": "Mongolian (Mongolian Script)",
"0x850": "Mongolian (Mongolian Script)",
"0000085d": "Inuktitut - Latin",
"0x85d": "Inuktitut - Latin",
"0000085f": "Central Atlas Tamazight",
"0x85f": "Central Atlas Tamazight",
"00000c04": "Chinese (Traditional, Hong Kong S.A.R.) - US Keyboard",
"0xc04": "Chinese (Traditional, Hong Kong S.A.R.) - US Keyboard",
"00000c0c": "Canadian French (Legacy)",
"0xc0c": "Canadian French (Legacy)",
"00000c1a": "Serbian (Cyrillic)",
"0xc1a": "Serbian (Cyrillic)",
"00000C51": "Dzongkha",
"0xc51": "Dzongkha",
"00001004": "Chinese (Simplified, Singapore) - US Keyboard",
"0x1004": "Chinese (Simplified, Singapore) - US Keyboard",
"00001009": "Canadian French",
"0x1009": "Canadian French",
"0000100c": "Swiss French",
"0x100c": "Swiss French",
"0000105f": "Tifinagh (Basic)",
"0x105f": "Tifinagh (Basic)",
"00001404": "Chinese (Traditional, Macao S.A.R.) - US Keyboard",
"0x1404": "Chinese (Traditional, Macao S.A.R.) - US Keyboard",
"00001809": "Irish",
"0x1809": "Irish",
"0000201a": "Bosnian (Cyrillic)",
"0x201a": "Bosnian (Cyrillic)",
"00004009": "India",
"0x4009": "India",
"00010401": "Arabic (102)",
"0x10401": "Arabic (102)",
"00010402": "Bulgarian (Latin)",
"0x10402": "Bulgarian (Latin)",
"00010405": "Czech (QWERTY)",
"0x10405": "Czech (QWERTY)",
"00010407": "German (IBM)",
"0x10407": "German (IBM)",
"00010408": "Greek (220)",
"0x10408": "Greek (220)",
"00010409": "United States-Dvorak",
"0x10409": "United States-Dvorak",
"0001040a": "Spanish Variation",
"0x1040a": "Spanish Variation",
"0001040e": "Hungarian 101-key",
"0x1040e": "Hungarian 101-key",
"00010410": "Italian (142)",
"0x10410": "Italian (142)",
"00010415": "Polish (214)",
"0x10415": "Polish (214)",
"00010416": "Portuguese (Brazilian ABNT2)",
"0x10416": "Portuguese (Brazilian ABNT2)",
"00010418": "Romanian (Standard)",
"0x10418": "Romanian (Standard)",
"00010419": "Russian (Typewriter)",
"0x10419": "Russian (Typewriter)",
"0001041b": "Slovak (QWERTY)",
"0x1041b": "Slovak (QWERTY)",
"0001041e": "Thai Pattachote",
"0x1041e": "Thai Pattachote",
"0001041f": "Turkish F",
"0x1041f": "Turkish F",
"00010426": "Latvian (QWERTY)",
"0x10426": "Latvian (QWERTY)",
"00010427": "Lithuanian",
"0x10427": "Lithuanian",
"0001042b": "Armenian Western",
"0x1042b": "Armenian Western",
"0001042c": "Azerbaijani (Standard)",
"0x1042c": "Azerbaijani (Standard)",
"0001042e": "Sorbian Extended",
"0x1042e": "Sorbian Extended",
"0001042f": "Macedonian (FYROM) - Standard",
"0x1042f": "Macedonian (FYROM) - Standard",
"00010437": "Georgian (QWERTY)",
"0x10437": "Georgian (QWERTY)",
"00010439": "Hindi Traditional",
"0x10439": "Hindi Traditional",
"0001043a": "Maltese 48-Key",
"0x1043a": "Maltese 48-Key",
"0001043b": "Sami Extended Norway",
"0x1043b": "Sami Extended Norway",
"00010444": "Tatar",
"0x10444": "Tatar",
"00010445": "Bengali - INSCRIPT (Legacy)",
"0x10445": "Bengali - INSCRIPT (Legacy)",
"00010451": "Tibetan (PRC) - Updated",
"0x10451": "Tibetan (PRC) - Updated",
"00010453": "Khmer (NIDA)",
"0x10453": "Khmer (NIDA)",
"0001045a": "Syriac Phonetic",
"0x1045a": "Syriac Phonetic",
"0001045b": "Sinhala - Wij 9",
"0x1045b": "Sinhala - Wij 9",
"0001045c": "Cherokee Nation Phonetic",
"0x1045c": "Cherokee Nation Phonetic",
"0001045d": "Inuktitut - Naqittaut",
"0x1045d": "Inuktitut - Naqittaut",
"00010465": "Divehi Typewriter",
"0x10465": "Divehi Typewriter",
"00010480": "Uyghur",
"0x10480": "Uyghur",
"0001080c": "Belgian (Comma)",
"0x1080c": "Belgian (Comma)",
"0001083b": "Finnish with Sami",
"0x1083b": "Finnish with Sami",
"00010850": "Traditional Mongolian (Standard)",
"0x10850": "Traditional Mongolian (Standard)",
"00010c00": "Myanmar (Phonetic order)",
"0x10c00": "Myanmar (Phonetic order)",
"00011009": "Canadian Multilingual Standard",
"0x11009": "Canadian Multilingual Standard",
"0001105f": "Tifinagh (Full)",
"0x1105f": "Tifinagh (Full)",
"00011809": "Gaelic",
"0x11809": "Gaelic",
"00020401": "Arabic (102) AZERTY",
"0x20401": "Arabic (102) AZERTY",
"00020402": "Bulgarian (Phonetic)",
"0x20402": "Bulgarian (Phonetic)",
"00020405": "Czech Programmers",
"0x20405": "Czech Programmers",
"00020408": "Greek (319)",
"0x20408": "Greek (319)",
"00020409": "United States-International",
"0x20409": "United States-International",
"0002040d": "Hebrew (Standard)",
"0x2040d": "Hebrew (Standard)",
"00020418": "Romanian (Programmers)",
"0x20418": "Romanian (Programmers)",
"00020419": "Russian - Mnemonic",
"0x20419": "Russian - Mnemonic",
"0002041e": "Thai Kedmanee (non-ShiftLock)",
"0x2041e": "Thai Kedmanee (non-ShiftLock)",
"00020422": "Ukrainian (Enhanced)",
"0x20422": "Ukrainian (Enhanced)",
"00020426": "Latvian (Standard)",
"0x20426": "Latvian (Standard)",
"00020427": "Lithuanian Standard",
"0x20427": "Lithuanian Standard",
"0002042b": "Armenian Phonetic",
"0x2042b": "Armenian Phonetic",
"0002042e": "Sorbian Standard",
"0x2042e": "Sorbian Standard",
"00020437": "Georgian (Ergonomic)",
"0x20437": "Georgian (Ergonomic)",
"00020445": "Bengali - INSCRIPT",
"0x20445": "Bengali - INSCRIPT",
"00020449": "Tamil 99",
"0x20449": "Tamil 99",
"0002083b": "Sami Extended Finland-Sweden",
"0x2083b": "Sami Extended Finland-Sweden",
"00020c00": "New Tai Lue",
"0x20c00": "New Tai Lue",
"00030402": "Bulgarian",
"0x30402": "Bulgarian",
"00030408": "Greek (220) Latin",
"0x30408": "Greek (220) Latin",
"00030409": "United States-Dvorak for left hand",
"0x30409": "United States-Dvorak for left hand",
"0003041e": "Thai Pattachote (non-ShiftLock)",
"0x3041e": "Thai Pattachote (non-ShiftLock)",
"0003042b": "Armenian Typewriter",
"0x3042b": "Armenian Typewriter",
"00030437": "Georgian Ministry of Education and Science Schools",
"0x30437": "Georgian Ministry of Education and Science Schools",
"00030c00": "Tai Le",
"0x30c00": "Tai Le",
"00040402": "Bulgarian (Phonetic Traditional)",
"0x40402": "Bulgarian (Phonetic Traditional)",
"00040408": "Greek (319) Latin",
"0x40408": "Greek (319) Latin",
"00040409": "United States-Dvorak for right hand",
"0x40409": "United States-Dvorak for right hand",
"00040437": "Georgian (Old Alphabets)",
"0x40437": "Georgian (Old Alphabets)",
"00040c00": "Ogham",
"0x40c00": "Ogham",
"00050408": "Greek Latin",
"0x50408": "Greek Latin",
"00050409": "US English Table for IBM Arabic 238_L",
"0x50409": "US English Table for IBM Arabic 238_L",
"00050429": "Persian (Standard)",
"0x50429": "Persian (Standard)",
"00060408": "Greek Polytonic",
"0x60408": "Greek Polytonic",
"00070c00": "Lisu (Basic)",
"0x70c00": "Lisu (Basic)",
"00080c00": "Lisu (Standard)",
"0x80c00": "Lisu (Standard)",
"00090c00": "N\u2019Ko",
"0x90c00": "N\u2019Ko",
"000a0c00": "Phags-pa",
"0xa0c00": "Phags-pa",
"000b0c00": "Buginese",
"0xb0c00": "Buginese",
"000c0c00": "Gothic",
"0xc0c00": "Gothic",
"000d0c00": "Ol Chiki",
"0xd0c00": "Ol Chiki",
"000e0c00": "Osmanya",
"0xe0c00": "Osmanya",
"000f0c00": "Old Italic",
"0xf0c00": "Old Italic",
"00100c00": "Sora",
"0x100c00": "Sora",
"00110c00": "Javanese",
"0x110c00": "Javanese",
"00120c00": "Futhark",
"0x120c00": "Futhark",
"00130c00": "Myanmar (Visual Order)",
"0x130c00": "Myanmar (Visual Order)",
"00140c00": "ADLaM",
"0x140c00": "ADLaM",
"00150c00": "Osage",
"0x150c00": "Osage"
}