簡體   English   中英

如何以編程方式按Enter鍵?

[英]How do I programmatically press Enter?

我有一個C#控制台程序,它啟動計算器並模擬按鍵。 如何以編程方式按Enter鍵

    [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?
    }

取自SendKeys.Send方法

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

要么

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM