void run(){ Display* display = XOpenDisplay(0); Window root = DefaultRootWindow(display); Window current_focus_window; int revert; XSetErrorHandler(MyX11ErrorHandler); XGetInputFocus(display, ¤t_focus_window, &revert); XSelectInput(display,current_focus_window,KeyPressMask | KeyReleaseMask | FocusChangeMask); while(true) { XEvent event; XNextEvent(display, &event); switch (event.type) { case FocusOut: if(current_focus_window != root) XSelectInput(display, current_focus_window, 0); XGetInputFocus(display, ¤t_focus_window, &revert); if(current_focus_window == PointerRoot) current_focus_window = root; XSelectInput(display, current_focus_window, KeyPressMask|KeyReleaseMask|FocusChangeMask); break; case KeyRelease: qDebug() << event.xkey.keycode; break; } } exec();}