[mythtv-users] Solution for using lirc-enabled remote with xmame.

Truls A. Tangstad kerfue+mythtv-users at herocamp.org
Mon Sep 27 13:39:47 EDT 2004

This might be slightly off-topic, but since I use my myth-box for also
running mame through mythgame, I thought the info might be of interest
to some subscribers.  Another reason for me posting this is that I had
a very hard time finding information on the web concerning xmame and
remote controls, except messages about irxevent not working, so I hope
this helps someone to have an easier time of making it work than I

I have a silent-running myth-box in my living room, connected to my TV
and network. Attached are a few joypads, a remote receiver and a
keyboard. I'm trying to get rid of needing the keyboard alltogether,
and at the moment xmame was the primary showstopper.

I have a hauppage-250 remote control and have it set up with lirc. I
was initially hoping to use irxevent (part of lirc) to send keypresses
to xmame, but for some reason xmame doesn't respond to the events at

The solution was using the X-extension library XTest through a perl[1] or
python[2] binding. I've only so far tested the python-binding, but it
is based directly on the perl source code. The python-binding seem to
have been created primarily to use an Ericsson phone as a remote, but
the keycontrol module[3] is useful for alot of other stuff (most
importantly xmame).

After compiling the pythoncode and moving the resulting keycontrol.so
shared library to a directory in your python-path, you can use the
binding in any python script like this:

import keycontrol
keycontrol.tapkey('k') # send k to desktop

The bindings use XTestFakeKeyEvent to send a keypress as if it came
from the keyboard itself, and works great with xmame.

To use it with a remote just use irexec (man irexec for more
instructions) which is a part of lirc, and for given keypresses make
it call the python-script (or perl-script) which presses the key.

Example pythonscript presskey.py:
# presskey.py
import keycontrol
import sys
for key in sys.argv:
    # assume each argument is the name of a key and press it

Set the script executable, place it in your path, and you can add
'presskey.py k' as a command in .lircrc for irexec to send the
keypress 'k' to the desktop when a certain remotecontrol button is
pressed. Many mamegames require you to press OK when starting, some of
which can be suppressed by using -skip_gameinfo and -skip_disclaimer.
To skip such a screen with the remote, one now only has to configure
irexec to run 'presskey.py o k' when hitting a given button on the

It might be useful to only enable irexec when xmame starts, then
disable it afterwards, which can be done by creating an xmame-wrapper
script doing just that. Place all your irexec-settings in
~/.xmame-lircrc, create the following script xmame-wrapper.sh, set it
executable and set it as the xmame-executable in the frontend setup of

# xmame-wrapper.sh
irexec ~/.xmame-lircrc &
xmame.x11 $@
killall irexec

One problem I haven't solved yet is pressing keys with modifiers. The
keycontrol.tapkey-function simulates pressing a key and releasing it
immediately, so doing stuff like shift-F9 mapped to one remote button
isn't possible without a slight rewrite of the module.

If someone is interested in examples of .lircrc-files for this use,
just reply to this list, and I can post mine as I get it polished.
If there's any interest, I might post some instruction on a website
with links to examples.

BTW: An alternative way of using the hauppauge remote (and probably
other remotes) is through the ir-kbd-i2c kernel module which makes the
remote act as an input device just like the keyboard. Lirc can be made
to work against the event device (/dev/input/event5 or similar) while
the remote can send keypresses to any program. This might work with
xmame, but I had a big problem with using the kernel module and that
was very sluggish response when pressing keys. Doing stuff like
volume adjustment required repeatedly pressing the buttons, even
though the repeat-value was set low in .lircrc. On the other hand it
might just have been me setting stuff up wrong. Feel free to try it
out as a alternative. YMMV.

Disclaimer: I haven't tested these scripts, the only thing I've tested
is the keycontrol-module. The scripts mentioned are just pointers to
possibilites of what can be done. Feel free to comment on mistakes or
better ways to do things. I am not the author of any of the programs
or bindings mentioned. And no... this posting was not intended to be
this long... *sigh*

[1] - http://sourceforge.net/projects/x11guitest
[2] - http://www.hackdiary.com/archives/000037.html
[3] - http://www.hackdiary.com/src/blueremote-1.0.tar.gz
Truls A. Tangstad - kerfue+mythtv-users at herocamp.org

More information about the mythtv-users mailing list