I’m writing a code to get the pressed key and block the keyboard input. Example: If the Super_L or Super_R key is pressed, prevent them to open a application menu. The code works while the program is opened, but when the program is closed the keys are sent to system. Example: If user press the Super_L key nothing happens while the program is running but when the program is closed, automatically the Ubuntu application menu is opened. How can i fix this issue?
void hook()
{
Display *dpy = XOpenDisplay(0);
XEvent ev;
if(!dpy)
{
qDebug() << "Error";
return;
}
XGrabKeyboard(dpy, DefaultRootWindow(dpy), false, GrabModeAsync, GrabModeAsync, CurrentTime);
forever
{
XNextEvent(dpy, &ev);
switch (ev.type)
{
case KeyPress:
qDebug() << "KeyPress" << XKeysymToString(XKeycodeToKeysym(dpy, ev.xkey.keycode, 0));
break;
case KeyRelease:
qDebug() << "KeyRelease" << XKeysymToString(XKeycodeToKeysym(dpy, ev.xkey.keycode, 0));
break;
}
}
}
Quoth the manual:
Grabs are requested by clients and granted to clients. For the duration of a grab, all relevant events are delivered to the grabbing client. No client, no grab.
I don’t see what’s to fix here. If you want a piece of functionality working, make sure the application that implements it is running.