title: Getting key name from keycode (X11 XGrabKey)
body: <p>I have a global key event handler in linux as below. I need to know which keyboard is grabbed. For example if key 'P' is pressed I get the corresponding key code. Is there any way to get the key name ("P") from this unsigned key code ? </p>
  
  <pre><code>#include &lt;xcb/xcb.h&gt;
  #include &lt;X11/Xlib.h&gt;
  #include &lt;X11/Xutil.h&gt;
  
  #include &lt;QtX11Extras/QX11Info&gt;
  
  void EventFilter::setup(QWidget *target)
  {
      this-&gt;target = target;
  
      Display * display = QX11Info::display();
      unsigned int modifiers = ControlMask;
      keycode = XKeysymToKeycode(display, XK_A);
      XGrabKey(display, keycode, modifiers, DefaultRootWindow(display), 1, GrabModeAsync, GrabModeAsync);
  }
  
  bool EventFilter::nativeEventFilter(const QByteArray &amp;eventType, void *message, long *)
  {
      if (eventType == "xcb_generic_event_t")
      {
          xcb_generic_event_t* xcbevent = static_cast&lt;xcb_generic_event_t *&gt;(message);
  
          switch(xcbevent-&gt;response_type)
          {
          case XCB_KEY_PRESS:
              xcb_key_press_event_t * keypress_event = static_cast&lt;xcb_key_press_event_t *&gt;(message);
              if(keypress_event-&gt;state &amp; XCB_MOD_MASK_CONTROL)
              {
                  if(keypress_event-&gt;detail == keycode)
                  {
                      //print key name here
                  }
              }
          }
      }
     return false;
   } 
  </code></pre>