簡體   English   中英

如何在后台工作的進程中模擬“輸入按鍵”?

[英]How to simulate "enter key press" in Process working in background?

在我的可執行Process實例中,我有幾個Console.ReadLine行。 如何在Process.InputStream類中傳遞Enter key press (模擬用戶Enter key press )? enter鍵應該如何在輸入字符串中查看?

// in string input I want to have information, that "user" pressed enter key  
this.Process.StandardInput.Write(input);

我的流程在后台工作,我已經設置了

this.Process.StartInfo.UseShellExecute = false;

旗幟。

編輯:

在我的exe文件中存在這樣的代碼:

   for (int i = 0; i < 3; i++)
   {
       array[i] = Console.ReadLine();
   }

我想在我的Process.StandardInput.Write模擬input string上的input string

您可以使用WriteLine()

this.Process.StandardInput.WriteLine();

或者您可以手動編寫換行序列。

this.Process.StandardInput.Write(this.Process.StandardInput.NewLine);

無論哪種方式都將AutoFlush設置為 true

this.Process.StandardInput.AutoFlush = true;

或在您寫入后手動刷新。

this.Process.StandardInput.Flush();

如果您想一次發送更多行,只需一次發送更多換行符,前面是您想要的任何文本。

this.Process.StandardInput.Write(  "a" + this.Process.StandardInput.NewLine
                                 + "b" + this.Process.StandardInput.NewLine);

暫無
暫無

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

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