C# SendKeys.SendWait to a dialog of another Process (notepad.exe)
问题 I'm trying to do the following in C#: Open a new process (notepad.exe) Enter some text (using SendKeys) Close Notepad (deal with any confirmation dialogs) Here's what I got Process p = new Process(); p.StartInfo.Filename = "notepad.exe"; p.Start(); // use the user32.dll SetForegroundWindow method SetForegroundWindow( p.MainWindowHandle ); // make sure notepad has focus SendKeys.SendWait( "some text" ); SendKeys.SendWait( "%f" ); // send ALT+f SendKeys.SendWait( "x" ); // send x = exit // a