从第二个键盘重定向键盘输入 [英] Redirect Keyboard input from second keypad

查看:175
本文介绍了从第二个键盘重定向键盘输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正处于为现有POS程序开发配套应用程序的初期阶段.基本上,我正在寻找类似针垫的功能.我们有一个Targus USB数字键盘,希望客户可以使用它输入PIN码. (这不是用于支付系统,仅用于客户帐户验证).主POS程序将运行,但是我需要我的应用程序在后台运行,并等待输入PIN,然后对其进行身份验证.

I'm in the initial stages of developing a companion application to an existing POS program. Basically I'm looking for pin pad like functionality. We have a Targus USB numerical keypad and want this available to the customer to enter a PIN number. (This is NOT for a payment system, just a customer account verification). The main POS program will be running, but I need my application to run in the background and wait for a PIN to be entered which it will then authenticate.

可能的解决方案1: 我从Code Project下载了一个示例项目,该示例项目通过VID& amp; PID.这将是完美的,但是键盘受到Windows的某种保护,因此无法通过这种方式进行访问.有没有一种方法可以在Windows中取消保留"键盘,使其仍然是HID设备,而不是键盘?

Possible Solution #1: I downloaded a sample project from Code Project that addresses USB HID devices by VID & PID. this would be perfect, however keyboards are somehow protected by Windows and cannot be accessed this way. Is there a way to "Unreserve" the keypad in Windows so its still a HID device, but not seen as a keyboard?

可能的解决方案2: 有一些键盘挂钩示例,但是这些都不起作用,因为键盘输出仍将转到POS应用程序.无论什么程序具有焦点,我都需要键盘输出仅进入我的后台应用程序.有没有一种方法可以将输出从特定的键盘重定向到特定的应用程序?

Possible Solution #2: There are samples of keyboard hooks, but these wont work either as the keypad output will still go to the POS application. I need the keypad output to ONLY go to my background application no matter what program has focus. Is there a way to redirect output from a specific keyboard to a specific application?

这将被部署到远程位置的100多个POS终端,因此不需要重新配置窗口的解决方案将是更好的选择.它还需要在C#.NET 2.0中

This will be rolled out to 100+ POS terminals in remote locations so a solution that doesn't require re-configuration of windows would be preferable. It also needs to be in C# .NET 2.0

推荐答案

您最好的选择是购买游戏杆键盘",以便您可以将设备(USB HID)读为非键盘/非鼠标(如键盘和鼠标受操作系统的限制,不可绕行,因为它们已硬编码到设备管理中.)

Your best option is to buy a Joystick "Keyboard" so that you can read the device (USB HID) as a non-keyboard/non-mouse (as keyboards and mice are restricted by OS, non-bypass-able because it's hard coded into the Device Management.)

我建议您使用PI Engineering的键盘,因为它们的键盘可以注册为操纵杆.他们拥有自定义的映射软件,该软件可以模拟在设备上按下按键以在Windows消息队列中发送按键(模拟键盘).相反,您可以使用其SDK直接针对设备进行编程(每个键只是一个操纵杆按钮),而不会干扰POS软件.

What I would recommend is looking an PI Engineering's keyboard as their keyboards can be registered as joysticks. They have custom mapping software that simulates pressing a key on their devices to sending a key in the windows messaging queue (simulating a keyboard). Instead you can just program directly against the device (As each key is just a joystick button) using their SDK and won't interfere with the POS software.

PI Engineering可编程键盘

USB访问说明(以下列出了相关部分,以防万一链接消失了)

USB access description (Relevant section listed below in case the link dies)

Microsoft Windows

Windows驱动程序开发工具包HID

Windows DDK HID API就像Apple HID Manager一样,它是一个复杂的低级API,与USB HID紧密镜像.程序可以访问或多或少地访问每个设备的输入和输出,但键盘和鼠标除外,Microsoft故意阻止了此API的访问.与到目前为止介绍的其他API不同,读取机制的性质使得在没有专用于从队列读取事件的线程的情况下很难使用它.乍看起来,似乎有必要购买Microsoft的驱动程序开发套件以使用此API,但可以将其与免费的MinGW工具一起使用.

The Windows DDK HID API is like the Apple HID Manager in that is a complicated, low-level API that closely mirrors USB HID. A program can access more or less every device, both input and output, except for the keyboard and mouse, which Microsoft has deliberately blocked from this API. Unlike the other APIs covered so far, the nature of the reading mechanism makes it quite difficult to use without having a thread dedicated to reading events from the queue. While at first glance it may seem necessary to purchase Microsoft's Driver Development Kit in order to use this API, it is possible to use it with the free MinGW tools.

在Windows中,设备插入和拔出事件的通知将发送到窗口句柄,因此要接收它们,hidio对象需要它自己的(不可见)窗口,然后该窗口可以接收通知.在当前实现中,对象在收到此类通知时会自动重建设备列表.此外,如果设备当前处于打开状态,则会检查该设备是否仍处于连接状态或已卸下.

In Windows, notifications of device plug and unplug events are sent to a window handle, so in order to receive them the hidio object needs it's own (invisible) window which can then receive the notifications. In the current implementation the object automatically rebuilds the device list when it receive such a notification. Additionally, in case a device is currently open it checks whether the device is still connected or got removed.

DirectInput

Microsoft的DirectInput API提供了一个相对简单的界面,但以牺牲灵活性为代价.它对USB HID设备类型的支持有限,并且主要针对最受欢迎的游戏设备.在使用USB HID的情况下,它仅支持通用桌面页面".它确实提供对鼠标和键盘数据的访问,但不能作为单独的设备访问.如果连接了多个鼠标或键盘,则所有数据都将集中到一个虚拟设备中.它确实支持强制反馈,但不支持其他任何输出类型.像Linux input.h一样,它具有自己的简化事件方案,并且还可以自动缩放某些传入的数据,这可能是有问题的.

Microsoft's DirectInput API provides a relatively straightforward interface, but at the expense of flexibility. It has limited support for the USB HID device types and mainly aimed at the most popular gaming devices; in USB HID-speak, it only supports the `Generic Desktop Page'. It does provide access to the mouse and keyboard data, but not as individual devices. If there are multiple mice or keyboards attached, then all of the data is lumped into one virtual device. It does support Force Feedback, but not any other output type. Like Linux input.h, it has its own simplified event scheme, and also automatically scales some of the incoming data, which can be problematic.

Windows Raw输入

Raw Input是Windows XP的新API,它是为响应开发人员对键盘和鼠标的原始访问的需求而提供的.这是从Windows上的鼠标和键盘获取原始数据的唯一方法.使用原始输入,可以获取任何USB HID设备的输入事件,但是根本不支持输出.因此,我们尚未深入研究Raw Input,但我们可能会使用它来完全支持Windows上的键盘和鼠标.

Raw Input is a new API as of Windows XP that was provided in response to developers' desire to get raw access to the keyboard and mouse. It is the only way to get raw data from mice and keyboards on Windows. With Raw Input, it is possible to get the input events for any USB HID device, but output is not supported at all. For this reason, we have not explored Raw Input deeply yet, but we will probably use it in order to fully support keyboards and mice on Windows.

这篇关于从第二个键盘重定向键盘输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆