title: Get mouse button state nonblocking linux
body: <p>I'm trying to write a plugin for a game and I need to read the state of the mouse button and not block or "eat" the events. Directly reading /dev/input is not an options because of root access.
  The closer I came to what I need is the following code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;X11/Xlib.h&gt;
  
  
  int main (int argc, char **argv)
  {
  Display *display;
  XEvent ev;
  
  display = XOpenDisplay(NULL);
  Window window = RootWindow(display, XDefaultScreen(display));
  
  XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask);
  XGrabButton(display, Button1, AnyModifier, window, False, ButtonPressMask | ButtonReleaseMask, GrabModeSync, GrabModeAsync, None, None);
  
  while(1) {
  
  XAllowEvents(display, ReplayPointer, CurrentTime);
      if(XCheckTypedEvent(display, ButtonPress ,&amp;ev))
      {
          printf("Button pressed\n");
      }
      else if(XCheckTypedEvent(display, ButtonRelease ,&amp;ev))
      {
          printf("Button relised\n");
      }
  
  }
  
  return 0;
  }
  </code></pre>
  
  <p>The problem is that by setting GrabModeSync and using  XAllowEvents with  ReplayPointer I am able to pass the event but I get the ButtonPress only. ButtonRelease is never captured but I need it. GrabModeAsync captures both events but "eats" the clicks. 
  Can anyone suggest a solution?
  10x</p>