To send the F4 key to another process you will have to activate that process
http://bytes.com/groups/net-c/230693-activate-other-process suggests:
- Get Process class instance returned by Process.Start
- Query Process.MainWindowHandle
- Call unmanaged Win32 API function "ShowWindow" or "SwitchToThisWindow"
You may then be able to use System.Windows.Forms.SendKeys.Send("{F4}") as Reed suggested to send the keystrokes to this process
EDIT:
The code example below runs notepad and sends "ABC" to it:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace TextSendKeys
{
class Program
{
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
static void Main(string[] args)
{
Process notepad = new Process();
notepad.StartInfo.FileName = @"C:\Windows\Notepad.exe";
notepad.Start();
// Need to wait for notepad to start
notepad.WaitForInputIdle();
IntPtr p = notepad.MainWindowHandle;
ShowWindow(p, 1);
SendKeys.SendWait("ABC");
}
}
}