Capture X keystrokes

Hi,

I’m the author of Snippits[1], a text expansion program for Linux.
Snippits types by generating X keystrokes, using the xte utility from
the xautomation suite. However, the way xte reads typed X characters is
a bit of a hack: it generates key commands to select back one word
(ctrl+shift+left), cut (ctrl+x), and then it reads the clipboard (using
xsel). This method is slow, error-prone, and ugly.

I was wondering if there was any way to capture X keystrokes as they are
generated. Does anyone know of a better method than above? I’m not
averse to using Ruby UI Toolkit bindings, if they have some method for
this.

Does anyone have any suggestions?

1: http://ben.kudria.net/code/snippits