среда, 17 сентября 2008 г.

Send keyboard messages to the program automatically

use SendKeys.SendWait and SendKeys.Send methods

example:

class SendKeysDemo{
static void Main()
{
// run program - notepad
Process process = Process.Start("notepad.exe");
// wait while the program ends initialization
process.WaitForInputIdle();
// find window of Notepad just run.

IntPtr hWndNotepad = FindWindow("Notepad", null);
// make found window active
SetForegroundWindow(hWndNotepad);
// send string
SendKeys.SendWait("Hello from GotDotNet.ru !!!");
}

// Export Win32 functions
[DllImport("User32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("User32.dll")]
static extern int SetForegroundWindow(IntPtr hWnd);

}

Комментариев нет: