Determine input from different devices

风格不统一 提交于 2021-01-28 06:59:52

问题


My PC has two devices working like keyboard, the normal keyboard and a HID (Human Interface Device) input device (it's a remote control).

I want separate the input from keyboard and from remote, capturing only the remote control. How can I write a program in C/C++ to do this task?

It's not a easy task because this program is operating system dependent. I need it for Windows, but if someone knows how to do it for Linux, I would appreciate that too.


回答1:


On Windows XP and later you can use raw input device messages. First you call the RegisterRawInputDevices() API function to enable raw input for "keyboards". You call GetRawInputDeviceList() to enumerate input devices and find the handle corresponding to your remote. Then you process the WM_INPUT window messages which contain raw input events, and check the header of the attached RAWINPUT structure to see whether the source device handle matches the handle you got earlier. If it does, you can continue processing the event.

Note the RIDEV_INPUTSINK flag, which may be useful to you. If you specify it, it makes your window receive WM_INPUT messages for events even if it is not the foreground window.




回答2:


I've done this under Linux - the device I had was a barcode reader that appears as a HID keyboard.

I did it by opening the corresponding event device in /dev/input, then using the EVIOCGRAB ioctl to "grab" the input device, which makes it exclusive to my application (events for that input device no longer go to X, or anything else). I then just read input events from the event device and act on them as appropriate.



来源:https://stackoverflow.com/questions/3463652/determine-input-from-different-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!