Guest User

Untitled

a guest
Jan 23rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. [DllImport("user32.dll")]
  2. private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  3.  
  4. [DllImport("user32.dll")]
  5. private static extern bool SetForegroundWindow(IntPtr hWnd);
  6.  
  7. public void SendTextToProcess(string processTitle, string textToSend)
  8. {
  9. IntPtr zero = IntPtr.Zero;
  10. for (int i = 0; (i < 10) && (zero == IntPtr.Zero); i++)//Пытается найти окно
  11. {
  12. Thread.Sleep(300);
  13. zero = FindWindow(null, processTitle);
  14. }
  15. if (zero != IntPtr.Zero)
  16. {
  17. SetForegroundWindow(zero);//делает окно активным (например консоли)
  18. SendKeys.SendWait(textToSend);//посылает нужные нажатия клавиш
  19. SendKeys.Flush();
  20. }
  21. }
  22.  
  23. SendTextToProcess("Untitled - Notepad", "hello World{ENTER}Tab{TAB}{TAB}test{TAB}{TAB}finished{ENTER}");
  24.  
  25. hello World
  26. Tab test finished
Add Comment
Please, Sign In to add comment