get-xkey.c (561B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <X11/Xlib.h> 4 5 int main(void) { 6 Display *dpy; 7 Window win; 8 XEvent e; 9 int s; 10 11 dpy = XOpenDisplay(NULL); 12 if (dpy == NULL) { 13 fprintf(stderr, "Cannot open display\n"); 14 exit(1); 15 } 16 17 s = DefaultScreen(dpy); 18 win = XCreateSimpleWindow(dpy, RootWindow(dpy, s), 10, 10, 100, 100, 0, 0, 0); 19 XSelectInput(dpy, win, ExposureMask | KeyPressMask); 20 XMapWindow(dpy, win); 21 22 while (1) { 23 XNextEvent(dpy, &e); 24 if (e.type == KeyPress) 25 printf("0x%x\n",e.xkey.keycode); 26 } 27 28 XCloseDisplay(dpy); 29 return 0; 30 }