Back to index

Making the Logitech Z-5 Infrared Remote Control work in Linux

Logitech Z-% IR Remote

The Logitech Z-5 USB Stereo Speakers are bundled with a small, simple infrared remote control. This device appears to Linux as an input event source (like a USB keyboard). This page shows how to read and act on events from the remote with a simple PHP script.

The /dev/input/event0 device

If you have no other USB input device connected, the Logitech Z-5 speakers will provide a /dev/input/event0 character device entry in Linux. By default, this device is only readable by root (otherwise any user would be allowed to do keylogging!). Creating a separate group 'input' and hacking a udev rule to set the gid of the event* devices to that 'input' group is one way to get around this restriction. I tried to follow the various guides here and here but couldn't get udev to apply the group. Haven't tried rebooting yet, though. In the meantime I just manually did a chgrp input /dev/input/event*.

Linux Input Event API (evdev)

The Linux Input Event API, or at least the parts we're concerned with, is fairly simple. Some documentation can be found in /usr/src/linux/Documentation/input/input.txt and include/linux/input.h. The important thing to notice is that read from the character event0 devices results in a structure like this: struct input_event {
   struct timeval time;
   __u16 type;
   __u16 code;
   __s32 value;
};
The interesting events are those with 'type' set to 0x0001 (see input.h, #define EV_KEY 0x01), which means keyboard events, and 'value' set to 0x00000001 (which according to input.txt means key down). The scan-code (i.e key identifier) is returned in the 'code' field. By experimentation, I've found the Logitech Z-5 remote control to produce the following scan codes:

Keycode
Volume down114 (KEY_VOLUMEDOWN)
Volume up115 (KEY_VOLUMEUP)
Previous165 (KEY_PREVIOUSSONG)
Next163 (KEY_NEXTSONG)
Play/Pause164 (KEY_PLAYPAUSE)
Music note button256 (BTN_MISC)
Power button113 (KEY_MUTE)

Putting it all together

Here's a simple PHP script that forever reads the /dev/input/event0 device, parses the resulting structs and acts on the relevant keypresses: z5input.phps (Run it from CLI via nohup or something, not through a web server)