I just found out that you can use xinput
to sniff key strokes across apps running on X
Is there something similar but to output data to whatever app has the focus now?
I would like to implement something like an autocomplete or smart suggestion program that listens for your keystrokes across applications and makes smart suggestion
e.g listen to whatever happens on the browser then if you switch to terminal or your text editor you can reuse some of that data.
You can send keyboard events to an X application using XSendEvent or the XTEST extension. XTEST is significantly more powerful, but in many cases it has to be manually enabled in the X server configuration. See also this and this for more information and some sample code.