模拟键盘CTRL+S 的输入
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Test_C_Shap
{
static class Program
{
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(IntPtr hWnd);
static void Main()
{
Process[] processes = Process.GetProcessesByName("notepad");
foreach (Process proc in processes)
{
SetForegroundWindow(proc.MainWindowHandle);
SendKeys.SendWait("^(s)");
}
}
}
}
添加System.Windows.Forms时要注意添加对应的dll文件
方法:Project-> Add Reference->Browse
浏览dll所在的文件夹,一般UI自动化的在WPF文件夹中,Forms一般在C:\Windows\Microsoft.NET\Framework\v4.0.30319(根据实际的version)