我正在编写一个应用程序,当应用程序本身不是 FOCUSED时,我需要更改系统的语言。恐怕唯一的方法是使用我目前无法完全理解的 windows 钩子。有什么想法吗?
编辑:解决方案
[DllImport("user32.dll")]
private static extern bool PostMessage(int hhwnd, uint msg, IntPtr wparam, IntPtr lparam);
[DllImport("user32.dll")]
private static extern IntPtr LoadKeyboardLayout(string pwszKLID, uint Flags);
private static uint WM_INPUTLANGCHANGEREQUEST = 0x0050;
private static int HWND_BROADCAST = 0xffff;
private static string en_US = "00000409";
private static uint KLF_ACTIVATE = 1;
private static void ChangeLanguage()
{
PostMessage(HWND_BROADCAST,WM_INPUTLANGCHANGEREQUEST, IntPtr.Zero ,LoadKeyboardLayout(en_US,KLF_ACTIVATE));
}