
如果记事本已经启动,则应输入:
// import the function in your class[Dllimport ("User32.dll")]static extern int SetForegroundWindow(IntPtr point);//...Process p = Process.GetProcessesByName("notepad").FirstOrDefault();if (p != null){ IntPtr h = p.MainWindowHandle; SetForegroundWindow(h); SendKeys.SendWait("k");}GetProcessesByName
返回一个进程数组,因此您应该获得第一个进程(或找到所需的进程)。
如果要启动
notepad并发送密钥,应输入:
Process p = Process.Start("notepad.exe");p.WaitForInputIdle();IntPtr h = p.MainWindowHandle;SetForegroundWindow(h);SendKeys.SendWait("k");代码可能无法正常工作的唯一情况是,当
notepad以Administrator身份启动而不是您的应用程序启动时。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)