开发者

Determine input from different devices

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 th开发者_C百科e 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜