@Cadoiz pointed you in the right direction。 According to MSDN返回的值其实是二:
要加载的输入语言环境标识符的名称。该名称是由语言标识符(低位字)的十六进制值和设备标识符(高位字)组成的字符串。例如,美国英语的语言标识符为 0x0409,因此主要的美国英语布局命名为“00000409”。美国英语布局的变体——(例如 Dvorak 布局)被命名为“00010409”、“00020409”等。
所以可以有很多组合,你需要的是第二个值。所以我想出了这个:
F1::
MsgBox % "Keyboard layout: " GetLayout(Language := "") "`n"
. "Keyboard language identifier: " Language
return
#if GetLayout(Language := "") = "gr"
a::MsgBox 0x40, Layout, % "Current layout: " Language
#if GetLayout(Language := "") = "us"
a::MsgBox 0x40, Layout, % "Current layout: " Language
#if
GetLayout(ByRef Language := "")
{
hWnd := WinExist("A")
ThreadID := DllCall("GetWindowThreadProcessId", "Ptr",hWnd, "Ptr",0)
KLID := DllCall("GetKeyboardLayout", "Ptr",ThreadID, "Ptr")
KLID := Format("0x{:x}", KLID)
Lang := "0x" A_Language
Locale := KLID & Lang
Info := KeyboardInfo()
return Info.Layout[Locale], Language := Info.Language[Locale]
}
KeyboardInfo()
{
static Out := {}
if Out.Count()
return Out
Layout := {}
loop reg, HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout\DosKeybCodes
{
RegRead Data
Code := "0x" A_LoopRegName
Layout[Code + 0] := Data
}
Language := {}
loop reg, HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layouts, KVR
{
RegRead Data
if ErrorLevel
Name := "0x" A_LoopRegName
else if (A_LoopRegName = "Layout Text")
Language[Name + 0] := Data
}
return Out := { "Layout":Layout, "Language":Language }
}