[libhid-discuss] how do I read events from a Hama MCE remote (keyboard+mouse)

Péter Szabó ptspts+libhid at gmail.com
Mon Oct 5 20:09:55 UTC 2009


Hi,

I have a Hama MCE remote control, whose USB dongle registers itself as
two HID devices on my machine running stock Ubuntu Jaunty 64-bit
desktop:

[210440.980030] usb 2-6: new low speed USB device using ohci_hcd and address 5
[210441.192962] usb 2-6: configuration #1 chosen from 1 choice
[210441.216468] input: HID 05a4:9881 as
/devices/pci0000:00/0000:00:04.0/usb2/2-6/2-6:1.0/input/input9
[210441.245334] generic-usb 0003:05A4:9881.0006: input,hidraw3: USB
HID v1.10 Keyboard [HID 05a4:9881] on usb-0000:00:04.0-6/input0
[210441.274963] input: HID 05a4:9881 as
/devices/pci0000:00/0000:00:04.0/usb2/2-6/2-6:1.1/input/input10
[210441.324278] generic-usb 0003:05A4:9881.0007: input,hidraw4: USB
HID v1.10 Mouse [HID 05a4:9881] on usb-0000:00:04.0-6/input1

Whenever I press a key on the remote, a few bytes become available for
reading on /dev/input/event7 or /dev/input/event8 (depending on the
key pressed; some of the keys emulate a mouse key, others emulate a
keyboard key).

So the hardware seems to work, keypresses can be propagated to
userspace (e.g. with `cat /dev/input/event7'). My questions are the
following:

1. How do I prevent the remote from sending keyboard events (such as
Enter, BackSpace, PageUp and numpad number keys) to the text-mode
virtual terminal and to X11? I don't want my remote to be recognized
as a regular keyboard or mouse -- but I have several USB keyboards and
mice connected to the computer, they should still be recognized as
such. Should I blacklist the USB device ID somewhere, possibly in
udev's configs? Exactly where and how?
2. Which is the easiest way to write a program which can dump the data
bytes received whenever a key is pressed on the remote, preferably in
human-readable form? How do I extract the keycode from the data? It
seems to me that using libhid is appropriate here. Do you have some
example code? If no, which functions should I call in which order?
3. How do I make my dumper program automatically be started whenever
the device gets connected, and how do I make it exit when the device
gets disconnected? Alternatively, if it's easier, it is OK that my
dumper program keeps running all the time, surviving connects and
disconnects.

I'm an experienced programmer in C, C++, Python, Ruby, Perl and a
bunch of other languages, so writing (or modifying) the dumper program
won't be a problem for me. I just need a kick start on USB HID device
configuration on Linux (kernel, modutils, udev etc.) and programming
device access with libhid (or without it, if it's easier), because I
haven't programmed USB device or set them up at low level yet.

Thanks a lot in advance,

Péter



More information about the libhid-discuss mailing list