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

Peter Stuge peter at stuge.se
Tue Oct 6 00:54:39 UTC 2009


Péter Szabó wrote:
> Hama MCE remote control
..

Linux knows this only as a USB keyboard and a USB mouse, since that
is how the dongle identifies itself. Like any other keyboard and
mouse, these are handled by the (kernel) input layer, which is what
provides you (processed) data in /dev/input/.


> 1. How do I prevent the remote from sending keyboard events
..
> I don't want my remote to be recognized as a regular keyboard or
> mouse

Too bad. That is how the device was built. The device type in USB is
stored in descriptors inside the device. Unless you want to hack the
dongle (extensively) you can not change this.


> Should I blacklist the USB device ID somewhere, possibly in udev's
> configs? Exactly where and how?

udev does you no good. The kernel USB stack identifies the devices,
and hooks them up to the kernel input layer, which then informs udev
that a new keyboard and mouse was attached.

If you're going to blacklist, it has to happen in the kernel HID
driver. Another option could be to detach the kernel drivers from
the devices in your application.


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

You would have to implement a USB keyboard driver, just like the one
in the kernel. You will spend time learning about USB programming in
general, and then with the USB HID Device Class specification, which
describes the layer on top of USB that applies to keyboards and mice.


> It seems to me that using libhid is appropriate here.

Yes and no. If you are doing this as a one-off project, you might
prefer using libusb or usbfs directly. libhid uses libusb, libusb
uses usbfs. usbfs is the Linux API for USB devices not handled by a
kernel driver.

Ideally you will find a way to not just use the kernel drivers.
/dev/input/event data is very easy to consume, you only really have
to block the keyboard and mouse within the HID layer. Maybe you can
get that done easily in the kernel.


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

This is udev. You create a udev rule or hotplug action which gets
triggered by device insertion. It starts your program. Your program
talks to the device, if the device goes away your program gets errors
and can exit or not.


> Alternatively, if it's easier, it is OK that my dumper program
> keeps running all the time, surviving connects and disconnects.

That works too. Maybe you can somehow use libudev to subscribe to
insertion notifications. I haven't used libudev so I don't know if it
can do that.


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

Read up on the USB 2.0 specification. USB is not just a serial port
with power but a multilayer protocol stack. The PDF is on usb.org
under Developers then Documents. Go for 2.0, while 3.0 is newer it's
mostly about a new higher speed mode. Start with 2.0, everything
there still very much applies.


//Peter



More information about the libhid-discuss mailing list