Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [DllImport("user32.dll")]
- private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [DllImport("user32.dll")]
- private static extern bool SetForegroundWindow(IntPtr hWnd);
- public void SendTextToProcess(string processTitle, string textToSend)
- {
- IntPtr zero = IntPtr.Zero;
- for (int i = 0; (i < 10) && (zero == IntPtr.Zero); i++)//Пытается найти окно
- {
- Thread.Sleep(300);
- zero = FindWindow(null, processTitle);
- }
- if (zero != IntPtr.Zero)
- {
- SetForegroundWindow(zero);//делает окно активным (например консоли)
- SendKeys.SendWait(textToSend);//посылает нужные нажатия клавиш
- SendKeys.Flush();
- }
- }
- SendTextToProcess("Untitled - Notepad", "hello World{ENTER}Tab{TAB}{TAB}test{TAB}{TAB}finished{ENTER}");
- hello World
- Tab test finished
Add Comment
Please, Sign In to add comment