title: XGrabKeyboard only blocks the keyboard while the program is running
body: <p>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?</p>
  
  <pre><code>void hook()
  {
      Display *dpy = XOpenDisplay(0);
      XEvent ev;
  
      if(!dpy)
      {
          qDebug() &lt;&lt; "Error";
          return;
      }
  
      XGrabKeyboard(dpy, DefaultRootWindow(dpy), false, GrabModeAsync, GrabModeAsync, CurrentTime);
  
      forever
      {
          XNextEvent(dpy, &amp;ev);
          switch (ev.type)
          {
          case KeyPress:
              qDebug() &lt;&lt; "KeyPress" &lt;&lt; XKeysymToString(XKeycodeToKeysym(dpy, ev.xkey.keycode, 0));
              break;
          case KeyRelease:
              qDebug() &lt;&lt; "KeyRelease" &lt;&lt; XKeysymToString(XKeycodeToKeysym(dpy, ev.xkey.keycode, 0));
              break;
          }
      }
  }
  </code></pre>