Windows – How to know which keyboard layout is currently active using cmd in Windows 7 32bit

command lineemacskeyboard-layoutwindows 7

Suppose I can switch between 3 keyboard layouts, English, German, and Spanish from the language bar of Windows 7 32bit. What command can be run from cmd to return the value of the current layout in use? My ultimate goal is to pass the returned value into an external editor (Emacs) so that it can change the font of the text based on the current keyboard layout.
That is, if I write a sentence in English the font will be font1, if in German font2, and so on. But that will only work if I can get some returned value (whether number of country locale or string line english, german, and so on) from the command line of Windows.

Best Answer

Edit: The below won't actually do what the OP requires as the values don't change when the keyboard is switched via the Language Bar shortcut, even though they do if you do it via the Control Panel. Leaving for completeness.

I cannot find any documented systeminfo or Powershell commands that may retrieve this information. I thought something like this may work, but alas none of the parameters for this or other cmdlets seem to be able to get hold of this setting.

powershell -Command "& {(Get-culture).keyboardlayoutid;}"

It seems Windows 8 may have added Powershell commands that do this, but in Windows 7 it does appear that you cannot detect changes made in this way.

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

The following will return the current keyboards:

reg query "HKEY_CURRENT_USER\Keyboard Layout\Preload"

This will return a list of all installed keyboards, with the one currently in use as 1.

HKEY_CURRENT_USER\Keyboard Layout\Preload
    1    REG_SZ    00000809
    2    REG_SZ    00000407
    3    REG_SZ    00000c0a

For reference, the values returned are listed here: msdn.microsoft.com/en-gb/goglobal/bb895996.aspx

Related Question