无法在我的 C# 项目中访问 Windows 输入模拟器
Can't access Windows Input Simulator in my C# project
研究了如何通过模拟键盘来控制其他应用程序,很多人建议我使用"inputsimulator" CodePlex
我解压缩文件夹并查找 .dll 文件以在我的 C# 项目中引用,但找不到 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
?
将这种依赖项引入项目的最佳方法是使用 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);
研究了如何通过模拟键盘来控制其他应用程序,很多人建议我使用"inputsimulator" CodePlex
我解压缩文件夹并查找 .dll 文件以在我的 C# 项目中引用,但找不到 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
?
将这种依赖项引入项目的最佳方法是使用 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);