[mythtv-users] Getting irxevent to work with SDL apps, game emulators (sdlmame, zsnes, fceux)

Matthew Sheppard mattjs12 at gmail.com
Sun Sep 6 22:50:33 UTC 2009

After finding irxevent failed to work with sdlmame, then searching and
finding two apps that did (xmacro and xdotool) I took a closer look.  I
found that a two line change to irxevent made it work.

Flushing the XEvent queue in between press and release and increasing
the sleep period is enough, I guess, to ensure the target window gets
the events in separate reads of its event queue.  SDL maybe ignoring the
event timestamp and treating a press-release in the same batch as
holding the key down for zero seconds.  Thus ignoring them.

sdlmame, zsnes, fceux had failed but then worked with the change below.
Another SDL game lbreakout2 worked before and after.  Probably affects
SDL apps that poll for events, rather than wait for next event.

*** lirc-0.8.4a/tools/irxevent.c        2007-03-30 19:13:47.000000000 +1200
--- lirc-0.8.4a/tools/irxevent.c.sdl-tweak      2009-09-02
11:44:58.000000000 +1200
*** 465,472 ****
    if (s) sendfocus(s,FocusIn);

    xev.type = KeyRelease;
!   usleep(2000);
    xev.xkey.time = fake_timestamp();
    if (s) sendfocus(s,FocusOut);
--- 465,474 ----
    if (s) sendfocus(s,FocusIn);

+   XFlush(dpy);
    xev.type = KeyRelease;
!   usleep(20000);
    xev.xkey.time = fake_timestamp();
    if (s) sendfocus(s,FocusOut);

I found the sleep period started to fail around 5000us.  20000us seemed
good.  It likely depends on x-server-side event buffering.  Then I found 
that sdlmame required very slow key presses in the menus (tab key) only. 
i.e. 70000us. I guess these aspects could ideally be options in each 
lircrc 'config' line.

I couldn't find any easy way to search lirc mailing list archive for
related postings.

Others experience with the problem:

posted to lirc-list AND mythtv-users.


More information about the mythtv-users mailing list