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

Charles Lepple clepple at ghz.cc
Mon Oct 5 22:50:40 UTC 2009


On Oct 5, 2009, at 4:09 PM, Péter Szabó wrote:

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

This is more of a udev question, and because Ubuntu ships with a lot  
of custom udev configuration files, your best bet may be to ask on an  
Ubuntu-specific list.

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

The simplest way might be to work with the event interface (and I am  
no expert there).

Assuming you want to use libhid, you would be interested in the code  
up to line 138 in the following file:

http://boxster.ghz.cc/projects/libhid/browser/trunk/test/test_libhid.c

The exact details vary (the kernel HID event layer hides a lot of the  
details) but you will probably want to use hid_interrupt_read():

http://libhid.alioth.debian.org/doc/hid_8h.html#41152a3e3d6c52a2aa3d7353463dc45b

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

You could do it either way, but IMHO the simplest way is to trigger  
off of a udev rule (since the permissions might not be set up before  
the udev rule runs, this can make reconnection messy).




More information about the libhid-discuss mailing list