简体   繁体   中英

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. 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. 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.

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. 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. 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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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