首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法访问我的C#项目中的Windows输入模拟器

无法访问我的C#项目中的Windows输入模拟器
EN

Stack Overflow用户
提问于 2019-05-09 03:07:45
回答 1查看 819关注 0票数 1

在研究了如何通过模拟键盘来控制其他应用程序之后,许多人建议我使用“输入模拟器”CodePlex

我解压该文件夹,并在我的C#项目中查找要引用的.dll文件,但我找不到inputsimulator.dll文件。

这是我到目前为止所知道的:

代码语言:javascript
复制
    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);
    }
    }

下面是错误消息:

代码语言:javascript
复制
'InputSimulator' does not contain a definition for 'SimulateKeyDown'

The name 'VirtualKeyCode' does not exist in the current context

如何引用InputSimulator

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-09 03:11:35

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

代码语言:javascript
复制
Install-Package InputSimulator -Version 1.0.4

您还可以从项目或解决方案文件的上下文菜单中使用"Manage NuGet Packages“选项。

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

此外,您引用的文档也是错误的。下面是一个例子。

您将需要using语句:

代码语言:javascript
复制
using WindowsInput;

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

代码语言:javascript
复制
var inputSim = new InputSimulator();
inputSim.Keyboard.KeyDown(WindowsInput.Native.VirtualKeyCode.RETURN);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56047492

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档