Please look at the code below to better understand what exactly I mean:
using System;
using System.Windows.Forms;
namespace CurrentInputLanguageTest
{
static class Program
{
[STAThread]
static void Main()
{
Console.WriteLine(InputLanguage.CurrentInputLanguage.LayoutName); // It's US
Console.ReadLine(); // Changed my keyboard layout while typing something
Console.WriteLine(InputLanguage.CurrentInputLanguage.LayoutName); // It's still US
var form = new Form();
var button = new Button();
button.Click += CheckInputLanguage;
form.Controls.Add(button);
Application.Run(form);
}
static void CheckInputLanguage(object sender, EventArgs e)
{
// I have changed my input language while the form is opened and pressed the button.
// It changes when called in this event handler.
Console.WriteLine(InputLanguage.CurrentInputLanguage.LayoutName);
}
}
}
The problem: I have some event handler in my app and I need to know what is current input language when the event is fired. How can I do this?