views:

48

answers:

2

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  A: 

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.

caf
this will help http://www.linuxjournal.com/article/6908
Kedar
+2  A: 

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.

slacker