static XEvent event; static char needinitxev=1; ... value of needinitxev does not change ... if(needinitxev) { memset(&event, 0, sizeof(event)); event.xkey.type=KeyPress; event.xkey.root=RootWindow(thedisp, thescreen); event.xkey.window=thewindow; /*event.xkey.subwindow=thewindow;*/ event.xkey.subwindow=0; /* My code, based on results from xev */ event.xkey.same_screen=True; event.xkey.display=thedisp; needinitxev=0; } event.xkey.time=CurrentTime; /* PoR is a variable passed to the function. It is of type: * enum {PRESS,RELEASE} */ event.xkey.type=PoR==PRESS ? KeyPress : KeyRelease; event.xkey.state=PoR==PRESS ? KeyPressMask : KeyReleaseMask; /* keycode is passed to the function */ event.xkey.keycode=keycode; event.xkey.x=50; event.xkey.y=50; XSendEvent(thedisp, thewindow, False, event.xkey.state, &event);