读取 HID 设备输入,例如从键盘或条形码扫描仪读取

发布于 2025-01-12 11:51:25 字数 1302 浏览 0 评论 0原文

所以我知道这个问题已经被问过很多次了,但我似乎找不到正确的答案。

有谁知道如何从任何 C#/.NET (.NET 6) 应用程序读取 HID 设备?

我尝试过几个软件包/项目,例如:

这些项目专注于从所有键盘并检查数据来自哪里。

现在我真正想要的是一个库/方法来从这些设备接收数据,而不需要 Windows 窗体句柄,甚至不需要关注应用程序。它应该以这样的方式工作:我可以简单地从设备获取数据,而不需要任何用户交互或关注应用程序,以便它可以从 .NET 控制台应用程序运行。

我发现的一个非常有趣的库是 HID.NET 库 (https://github.com/MelbourneDeveloper/Device .Net),这个库的问题之一是我遇到了与这个人相同的问题(https://github.com/MelbourneDeveloper/Device.Net/issues/88)。 因此它表明访问被拒绝打开设备进行读取。

这意味着我也无法使用这个库。

因此我觉得也许这里有人可以进一步帮助我。我想要任何可以进一步解决这个问题的方向。

非常感谢。

So I know this question has been asked many times, but I cannot seem to find a proper answer.

Does anyone know how to read from a HID device from any C#/.NET (.NET 6) application?

I've tried several packages/projects, such as:

These projects are focussed on fetching data from all keyboards and checking where the data came from.

Now what I'm really looking for is a library/way to receive data from these devices without needing a windows forms handle or even focus to the application. It should work in such a way that I can simply get the data from the device without requiring any user interaction or focus on the application, so that it would work from a .NET console application.

One really interesting library I found is the HID.NET library (https://github.com/MelbourneDeveloper/Device.Net), one of the issues with this library is that I get the same issue as this guy (https://github.com/MelbourneDeveloper/Device.Net/issues/88).
So it states that access is denied to open the device for reading.

This means I cannot use this library either.

Therefore I felt like maybe someone on here could help me further. I would like any direction in which I could go to get further with this issue.

Many thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅此而已 2025-01-19 11:51:25

非常奇怪的是,微软选择以所谓的“独占模式”打开此类设备,请参阅:
https: //learn.microsoft.com/en-us/windows-hardware/drivers/hid/hid-architecture#hid-clients-supported-in-windows

这表明这些设备已打开在独占模式下:

  • 鼠标类驱动程序和映射器驱动程序
  • 键盘/小键盘类驱动程序和映射器驱动程序
  • 外部笔设备
  • 集成笔设备
  • 触摸屏
  • 精密触摸板 (PTP)

关于此独占模式,它们说明如下:

在上表中,输入的访问模式HID 客户端具有独占性,可防止其他 HID 客户端在不是该输入的目标接收者时拦截或接收全局输入状态。因此,出于安全原因,RIM(原始输入管理器)专门开放所有此类设备。

如果设备通过 RIM(原始输入管理器)以独占模式打开,用户仍然可以打开 HID 设备接口,而无需请求读写权限,并通过 HIDClass 支持例程 (HidD_GetXxx) 获取 HID 设备信息。

这意味着我正在尝试做的事情,因此接收 USB-HID 包永远不会被允许(?),因此不是一个选项。
为了实现我想要的功能,可以选择将驱动程序切换到自定义 HID 或 COMport。

Very curiously, Microsoft chose to open these sort of devices in so called "Exclusive mode", see:
https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/hid-architecture#hid-clients-supported-in-windows

This states that these devices are opened in Exclusive mode:

  • Mouse class driver and mapper driver
  • Keyboard / Keypad class driver and mapper driver
  • External Pen Device
  • Integrated Pen Device
  • Touchscreen
  • Precision Touchpad (PTP)

About this exclusive mode, they state the following:

In the preceding table, the access mode for input HID clients is Exclusive to prevent other HID clients from intercepting or receiving global input state when they are not the target recipient of that input. Therefore, for security reasons RIM (Raw Input Manager) opens all such devices exclusively.

If device is opened in Exclusive mode by RIM (Raw Input Manager) user can still open HID device interface without requesting read and write permissions and obtain HID device information via HIDClass support routines (HidD_GetXxx).

This means that what I'm trying to do, so receive the USB-HID packages shall never(?) be allowed and is therefore not an option.
In order to achieve such functionality as I desire, switching drivers to custom HID or COMport can be an option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文