在研究了如何通过模拟键盘来控制其他应用程序之后,许多人建议我使用“输入模拟器”CodePlex
我解压该文件夹,并在我的C#项目中查找要引用的.dll文件,但我找不到inputsimulator.dll文件。
这是我到目前为止所知道的:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using WindowsInput;
public class WindowHandling
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
static void Main()
{
InputSimulator.SimulateKeyDown(VirtualKeyCode.SHIFT);
}
}下面是错误消息:
'InputSimulator' does not contain a definition for 'SimulateKeyDown'
The name 'VirtualKeyCode' does not exist in the current context如何引用InputSimulator
发布于 2019-05-09 03:11:35
将这种依赖项引入项目的最佳方法是使用NuGet
Install-Package InputSimulator -Version 1.0.4您还可以从项目或解决方案文件的上下文菜单中使用"Manage NuGet Packages“选项。
NuGet将下载该包,将其解压缩,然后将DLL添加到您的项目中。它还可以告诉您包何时更新。
此外,您引用的文档也是错误的。下面是一个例子。
您将需要using语句:
using WindowsInput;在你的代码中,你需要一个实例:
var inputSim = new InputSimulator();
inputSim.Keyboard.KeyDown(WindowsInput.Native.VirtualKeyCode.RETURN);https://stackoverflow.com/questions/56047492
复制相似问题