In this program written below, using the GetKeyboardLayoutName from user32.dll. When I type the first symbol using the "English USA" layout, I get 00000409. This is fine. But when I change my layout to something else, like "English UK" or "Russian", GetKeyboardLayoutName returns the code for "English USA" - 00000409.
I tested this and if I input the first symbol in "Russian", it returns 00000419 and if I switch back to "English USA" and input a second symbol, GetKeyboardLayoutName still returns the code for "Russian" - 00000419.
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace ConsoleApp2
{
class Program
{
const int KL_NAMELENGTH = 9;
[DllImport("user32.dll")]
private static extern long GetKeyboardLayoutName(StringBuilder pwszKLID);
public static string GetLayoutCode()
{
var name = new StringBuilder(KL_NAMELENGTH);
GetKeyboardLayoutName(name);
return name.ToString();
}
static void Main(string[] args)
{
Console.ReadKey();
var res = GetLayoutCode();
Console.WriteLine("\n" + res);
Console.ReadKey();
res = GetLayoutCode();
Console.WriteLine("\n" + res);
}
}
}