Skip to content

Instantly share code, notes, and snippets.

@wwalker
Created November 12, 2019 03:27
Show Gist options
  • Save wwalker/47b735ce5c64e1c59748b3b64ab29ab4 to your computer and use it in GitHub Desktop.
Save wwalker/47b735ce5c64e1c59748b3b64ab29ab4 to your computer and use it in GitHub Desktop.
#include "grab-keyboard.h"
static int ApplicationErrorHandler(Display *display, XErrorEvent *theEvent)
{
exit(127); /* clearly we aren't calling the error handler :-( */
(void) fprintf(stderr,
"Ignoring Xlib error: error code %d request code %d\n",
theEvent->error_code,
theEvent->request_code) ;
/* No exit! - but keep lint happy */
return 0 ;
}
int main(int argc, char **argv)
{
Display *dpy;
int x=0;
XEvent ev;
if((dpy = XOpenDisplay(NULL)) == NULL) {
perror(argv[0]);
exit(1);
}
XSetErrorHandler(&ApplicationErrorHandler);
XGrabKeyboard(dpy, 0x3c00022,
False, GrabModeAsync, GrabModeAsync, CurrentTime);
for (x=0;x<=10; x++) {
XNextEvent(dpy, &ev);
if ( ev.type == KeyPress || ev.type == KeyRelease ) {
ev.xkey.window = 0x3c00022;
printf("%d\n", XSendEvent(dpy, 0x3c00022, False, NoEventMask, &ev));
XSync(dpy, 1);
}
}
XUngrabKeyboard(dpy, CurrentTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment