1

在研究了如何通过模拟键盘来控制其他应用程序之后,很多人建议我使用“inputsimulator” 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

4

1 回答 1

1

将这种依赖项引入项目的最佳方法是使用 NuGet

Install-Package InputSimulator -Version 1.0.4

您还可以从项目或解决方案文件的上下文菜单中使用“管理 NuGet 包”选项。

NuGet 将下载包,解压缩,然后将 DLL 添加到您的项目中。它还可以告诉您软件包何时更新。

此外,您引用的文档也很遥远。这是一个例子。

您将需要 using 语句:

using WindowsInput;

在您的代码中,您需要一个实例:

var inputSim = new InputSimulator();
inputSim.Keyboard.KeyDown(WindowsInput.Native.VirtualKeyCode.RETURN);
于 2019-05-08T19:11:35.017 回答