Created
July 29, 2014 04:21
-
-
Save jouyouyun/669726de58df8d333666 to your computer and use it in GitHub Desktop.
Test XGrabKey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jouyouyun having the same problem as @skynowa...
I read this somewhere, which my be the reason: