Can';t在我的C#项目中访问Windows输入模拟器
在研究了如何通过模拟键盘控制其他应用程序后,许多人建议我使用“inputsimulator” 我解压缩了文件夹并在我的C#项目中查找要引用的.dll文件,但找不到inputsimulator.dll文件 以下是我到目前为止的情况:Can';t在我的C#项目中访问Windows输入模拟器,c#,dll,window,dllimport,inputsimulator,C#,Dll,Window,Dllimport,Inputsimulator,在研究了如何通过模拟键盘控制其他应用程序后,许多人建议我使用“inputsimulator” 我解压缩了文件夹并在我的C#项目中查找要引用的.dll文件,但找不到inputsimulator.dll文件 以下是我到目前为止的情况: using System; using System.Runtime.InteropServices; using System.Windows.Forms; using WindowsInput; public class
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?将这种依赖关系引入项目的最佳方法是使用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);
在哪里输入“InstallPackageInputSimulator-Version1.0.4”文档有点轻量级。。。能否创建
InputSimulator
的实例,例如InputSimulator inputSim=new InputSimulator()代码>?然后执行类似[code]inputSim.SimulateKeyDown(VirtualKeyCode.SHIFT)?我的答案中增加了一个例子。我刚刚下载了这个包,我的示例已经编译好了。这与文档完全不同(但公平地说,Codeplex是存档的)。我的声誉分数不到15,所以我无法投票哈哈,但我将你的帖子标记为答案。