我如何以编程方式按Enter

本文关键字:方式按 Enter 编程 | 更新日期: 2023-09-27 18:18:47

我有一个c#控制台程序,它启动计算器并模拟按键。如何以编程方式按进入?

    [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
    public static extern IntPtr FindWindow(string lpClassName,
        string lpWindowName);
    // Activate an application window.
    [DllImport("USER32.DLL")]
    public static extern bool SetForegroundWindow(IntPtr hWnd);
    // Send a series of key presses to the Calculator application. 
    private void StartCalculator()
    {
        Process.Start("calc.exe");
        IntPtr calculatorHandle = FindWindow("CalcFrame","Calculator");
        if (calculatorHandle == IntPtr.Zero)
        {
            return;
        }
        SetForegroundWindow(calculatorHandle);
        SendKeys.SendWait("111");
        SendKeys.SendWait("*");
        SendKeys.SendWait("11");
        SendKeys.SendWait("=");
        SendKeys.SendWait(" ");//how press enter?
    }

我如何以编程方式按Enter

取自SendKeys。发送方法

SendKeys.SendWait("~"); // How to press enter?

SendKeys.SendWait("{ENTER}"); // How to press enter?