@neauoire i don't in general see how the program could know what "the previously focused window" is. I don't think X keeps track of it. Do you have other means of knowing it? (if you do, it seems like you could modify xfake.c to send an event to any particular window; X definitely supports that).
@drj I'm not sure, is there a way I could send events to a particular window by recording which window I could out to, from my program? Like, if I loose focus to focus on a second window, is there a way to know that window's id?