Linux x11 keyboard hook
-
Hello,
I want to create an application that can capture keyboard in the application until the user press a certain keystroke as VM do.
I did that on windows with windows.h but now, I am on linux and my program don't work (as expected because I have used windows.h).
My problem is that when I try to include X11 in my project I have a lots of errors (556):
https://pastebin.com/1d7G8r5f
Do you know how to do that?
I am on arch linux with kde and x11Thanks in advance for your help.
-
@Robotechnic said in Linux x11 keyboard hook:
Do you know how to do that?
The X11 headers do some weird defines. Include them after the Qt includes or undefine them before including Qt headers.
-
Thanks @Christian-Ehrlicher , now the code work bu only in main:
int main(int argc, char *argv[]) { bool quit = false; Display *d = XOpenDisplay(NULL); XGrabKeyboard(d, DefaultRootWindow(d), true, GrabModeAsync, GrabModeAsync, CurrentTime); while(!quit) { XEvent ev; XNextEvent(d, &ev); switch (ev.type) { case KeyPress: char *s; unsigned int kc; kc = ((XKeyPressedEvent*)&ev)->keycode; s = XKeysymToString(XKeycodeToKeysym(d, kc, 0)); if(s) { qDebug()<<"Key :"<<s; } if(!strcmp(s, "q")) quit=~0; } } XUngrabKeyboard(d, CurrentTime); if (XCloseDisplay(d)) { return 1; } return 0; }
When I try to put in in QMainWindows errors happen
-
Will not work the way you do it - you block the Qt event loop.
-
Ok, so how can I do it?
-
Sorry my question is not for the Qt main loop, I can do that with thread or QTimer this is not my problem.
My problem was that when I have putted x11 headers in .h file, that generated errors but I fixed it and It work. Thanks @Christian-Ehrlicher , I have writing before thinking.