To switch the input language to English in C#, you can use the following code:

using System;
using System.Runtime.InteropServices;

public class InputLanguageSwitcher
{
    private const int WM_INPUTLANGCHANGEREQUEST = 0x0050;

    [DllImport('user32.dll')]
    private static extern IntPtr GetForegroundWindow();

    [DllImport('user32.dll')]
    private static extern IntPtr PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

    public static void SwitchToEnglish()
    {
        IntPtr foregroundWindow = GetForegroundWindow();
        PostMessage(foregroundWindow, WM_INPUTLANGCHANGEREQUEST, IntPtr.Zero, new IntPtr(0x0409)); // 0x0409 is the language code for English
    }
}

You can then call the SwitchToEnglish() method whenever you want to switch the input language to English.

C# Switch Input Language to English: Code Example

原文地址: https://www.cveoy.top/t/topic/9p0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录