为模拟输入设备编写 Windows 驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1394260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:06:14  来源:igfitidea点击:

Writing a windows driver for an emulated input device

windowsinputdevice-driver

提问by

My application needs to behave as a virtual joystick (imagine dragging a square with the mouse and translating that to the output of an analog joystick) and send some keystrokes over the network to another computer where the driver would receive that input.

我的应用程序需要充当虚拟操纵杆(想象一下用鼠标拖动一个方块并将其转换为模拟操纵杆的输出)并通过网络将一些按键发送到另一台计算机,驱动程序将在那里接收该输入。

I only need to support XP, Vista and Win7.

我只需要支持 XP、Vista 和 Win7。

Maybe it can be done without writing a driver. I tried sending keystrokes with SendKey() which seemed to work but don't know how to emulate an analog joystick.

也许不用写驱动就可以做到。我尝试使用 SendKey() 发送击键,这似乎有效,但不知道如何模拟模拟操纵杆。

I've downloaded the VDK and been reading everything I can find on the subject but there are lots of things I still don't understand. Can you please point me in the right direction?

我已经下载了 VDK 并阅读了我能找到的关于该主题的所有内容,但仍有很多我不明白的地方。你能指出我正确的方向吗?

  1. Should I build a kernel-mode or user-mode driver?
  2. Can my driver act as a server for an app on the network?
  3. Do you know good tutorials / books / samples that can help me with this.
  1. 我应该构建内核模式还是用户模式驱动程序?
  2. 我的驱动程序可以充当网络上应用程序的服务器吗?
  3. 你知道可以帮助我解决这个问题的好的教程/书籍/示例吗?

Thanks

谢谢

回答by Dale

First of all you will have to have some kind of interface between your computer (or the network) and the joystick device that is being controlled.

首先,您的计算机(或网络)和被控制的操纵杆设备之间必须有某种接口。

If it involves making custom hardware to control the analog joystick (like it controls pneumatics or hydraulics or something, not just a pc game joystick type thing), then yes, you will almost certainly need a driver to allow a network app to move (the robot arm, or whatever) will move that joystick.

如果它涉及制作自定义硬件来控制模拟操纵杆(比如它控制气动或液压或其他东西,而不仅仅是 PC 游戏操纵杆类型的东西),那么是的,您几乎肯定需要一个驱动程序来允许网络应用程序移动(机器人手臂或其他任何东西)将移动该操纵杆。

If you are able to remove the physical joystick from the equation, maybe you can write software that emulates the input of wherever the joystick used to plug into (a joystick/serial port?), or emulates it completely (a reasonably simple driver could do this). You could do it completely without writing a driver if the joystick used a standard communication interface (like RS232) because libraries exist that will handle all that and you can set up virtual COM ports that will be indistinguishable to whatever you are trying to communicate with.

如果您能够从方程中删除物理操纵杆,也许您可​​以编写软件来模拟操纵杆插入的任何位置的输入(操纵杆/串行端口?),或者完全模拟它(一个相当简单的驱动程序可以做到)这个)。如果操纵杆使用标准通信接口(如 RS232),您可以完全不编写驱动程序,因为存在的库可以处理所有这些,并且您可以设置虚拟 COM 端口,这些端口与您尝试与之通信的任何内容都无法区分。

The best book you can buy on driver development at the moment is Developing Drivers with the Windows Driver Foundation

您目前可以买到的关于驱动程序开发的最好的书是使用 Windows 驱动程序基础开发驱动程序

Rootkits: Subverting the Windows Kernelis another great book, but doesn't cover a lot of the newer WDF stuff. It has more of a security focus but has a few awesome chapters on device drivers with fully spoonfed examples, breaking it down in a really accessible way.

Rootkits: Subverting the Windows Kernel是另一本好书,但没有涵盖很多较新的 WDF 内容。它有更多的安全重点,但有一些关于设备驱动程序的精彩章节,带有完全勺子馈送的示例,以一种非常易于理解的方式对其进行分解。

回答by Alphaneo

If it is only over the network, probably simple socket programming should be enough.

如果只是通过网络,可能简单的套接字编程就足够了。