I am designing an on screen keyboard,
I need to determine which language been set by the user and which language he is using now in the other threads,
i.e. I need to know the language selected in the taskbar language switcher:
P.S. current culture returns the language used in the on screen keyboard application, which is not the case I am looking for..
The solution was to get the Keyboard Layout for the foreground window, and then apply it to the on screen keyboard, and check for the language in the usual ways..
IntPtr fore = GetForegroundWindow();
uint tpid = GetWindowThreadProcessId(fore, IntPtr.Zero);
IntPtr hKL = GetKeyboardLayout(tpid);
hKL = (IntPtr)(hKL.ToInt32() & 0x0000FFFF);
InputLanguageManager m = InputLanguageManager.Current;
m.CurrentInputLanguage = new System.Globalization.CultureInfo(hKL.ToInt32());
//IntPtr i = LoadKeyboardLayout(hKL.ToString(), 1);
InputLanguage = InputLanguageManager.Current.CurrentInputLanguage.ToString();
you can also get using WMI:
using System;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_BIOS");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_BIOS instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("CurrentLanguage: {0}", queryObj["CurrentLanguage"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With