您的位置:首页 > 编程语言 > C#

c#调用winAPI向某一程序发送按键

2013-03-10 19:56 441 查看
1:通过FindWindow找到窗体

2:通过SetForegroundWindow激活找到的窗体

3:发送按键

声明:

[DllImport("USER32.DLL")]
public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);


调用:

IntPtr calculatorHandle = FindWindow(null, "Form1");//窗口名称
if (calculatorHandle == IntPtr.Zero)
{
MessageBox.Show("not running.");
return;
}

SetForegroundWindow(calculatorHandle);
SendKeys.SendWait("111");
SendKeys.SendWait("*");
SendKeys.SendWait("11");
SendKeys.SendWait("=");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: