Pat*_*ald 11
要将F4密钥发送到另一个进程,您必须激活该进程
http://bytes.com/groups/net-c/230693-activate-other-process建议:
然后,您可以使用System.Windows.Forms.SendKeys.Send("{F4}"),因为Reed建议将按键发送到此进程
编辑:
下面的代码示例运行记事本并向其发送"ABC":
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");
}
}
}
Run Code Online (Sandbox Code Playgroud)