Skip to content

Instantly share code, notes, and snippets.

@jouyouyun
Created July 29, 2014 04:21
Show Gist options
  • Save jouyouyun/669726de58df8d333666 to your computer and use it in GitHub Desktop.
Save jouyouyun/669726de58df8d333666 to your computer and use it in GitHub Desktop.
Test XGrabKey
//Compile: gcc xgrabkey.c `pkg-config --cflags --libs x11`
#include <stdio.h>
#include <X11/Xlib.h>
int
main ()
{
Window root;
Display *dpy = NULL;
dpy = XOpenDisplay(0);
if (dpy == NULL) {
printf("Open Display Failed\n");
return -1;
}
root = DefaultRootWindow(dpy);
unsigned int mod = 0;
mod = mod| ControlMask|ShiftMask;
XGrabKey(dpy, AnyKey, mod, root, True, GrabModeAsync, GrabModeAsync);
XEvent event;
for (;;) {
XNextEvent(dpy, &event);
printf("Key event\n");
if (event.type == KeyPress) {
printf("Key press\n");
}
}
XAllowEvents(dpy, AsyncKeyboard, CurrentTime);
XUngrabKey(dpy, AnyKey, AnyModifier, root);
XSync(dpy, False);
XCloseDisplay(dpy);
return 0;
}
@jouyouyun
Copy link
Author

???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment