简体   繁体   English

可以将键盘输入绑定到 Win32 中的单个应用程序吗?

[英]Possible to Tie Keyboard Input to a Single Application in Win32?

I have a rather unusual Windows project for a client that has led me to believe that what we're trying to accomplish may not be possible.我有一个相当不寻常的 Windows 项目,它让我相信我们试图完成的事情可能是不可能的。 We're at a point where we would like to have the application listen for input from a proprietary keyboard device and process it.我们正处于希望让应用程序侦听来自专有键盘设备的输入并对其进行处理的地步。 This application runs in the background and always listens using an input sink with raw input.此应用程序在后台运行,并始终使用带有原始输入的输入接收器进行侦听。

Since the device is a keyboard, the foreground window always gets the input and our application will hear it as well.由于设备是一个键盘,前台 window 总是得到输入,我们的应用程序也会听到它。 Ideally, we would like ours to be the only one that hears input from the device.理想情况下,我们希望我们的设备是唯一能听到设备输入的设备。 As far as I could research, there doesn't seem to be any way to tie input from a specific device to a specific application and make every other application ignore it.据我研究,似乎没有任何方法可以将来自特定设备的输入绑定到特定应用程序并让所有其他应用程序忽略它。 I saw BlockInput() but that shuts down user input from every device.我看到了BlockInput()但这会关闭每个设备的用户输入。

Is this even possible?这甚至可能吗?

EDIT: To clarify some things, the device is seen as a keyboard by the system and I am able to use raw input to detect it as a keyboard and get the keystrokes.编辑:为了澄清一些事情,该设备被系统视为键盘,我可以使用原始输入将其检测为键盘并获取击键。 As a keyboard device, any foreground window will receive keystrokes when the user interacts with it.作为键盘设备,任何前台 window 都会在用户与其交互时接收击键。 The application listens for keystrokes from that device before taking a specific action.该应用程序在采取特定操作之前侦听来自该设备的击键。 I only want the application to receive input.我只希望应用程序接收输入。

After some additional testing, blocking with a WH_KEYBOARD hook was only partially reliable.经过一些额外的测试,使用WH_KEYBOARD钩子进行阻塞只是部分可靠。 It did not work with the newer-style Windows Store applications or higher-level ones, even after moving the DLL and adjusting the permissions as I have read from others.即使在移动 DLL 并按照我从其他人那里读到的权限调整后,它也不适用于更新样式的 Windows Store 应用程序或更高级的应用程序。 Furthermore, it would often miss out or get duplicate hook messages depending on what I was trying to do.此外,根据我的尝试,它经常会错过或得到重复的钩子消息。

WH_KEYBOARD_LL was more reliable, but it could not be used because it came before the raw input messages which identified the device. WH_KEYBOARD_LL更可靠,但不能使用,因为它出现在识别设备的原始输入消息之前。

I've come to the conclusion that the only reliable way to do this is through low-level driver/kernel programming.我得出的结论是,唯一可靠的方法是通过低级驱动程序/内核编程。 That's a completely different can of worms, and I'm not going to look for a can opener.那是完全不同的蠕虫罐头,我不打算寻找开罐器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM