解决方法
要将F4键发送到另一个进程,您将必须激活该进程
http://bytes.com/groups/net-c/230693-activate-other-process建议:
>获取Process.Start返回的类实例
> Query Process.MainWindowHandle
>调用非托管Win32 API函数“ShowWindow”或“SwitchToThisWindow”
然后,您可以使用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"); } } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。