title: XSelectInput is not working for ButtonPressEvents,how to do it?
body: <p>I am writing a simple programmes in C where i want to capture all the mouse and Keyboard events that are taking place.
  I tried to use "XGrabPointer" but it results in locking the screen and i can not go to other applications.
  I tried with "XSelectInput()" and now i am receiving the keyboard events successfully but i am not getting any mouse click events.</p>
  
  <p>Any idea how can i do it?</p>
  
  <p>The code snippet is as follows:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;X11/Xlib.h&gt;
  #include &lt;X11/Xutil.h&gt;
  #include &lt;X11/keysym.h&gt;
  
  int main(int argc, char **argv)
  {
     Display *dpy;
     Window root;
    unsigned long event_mask;
      event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask | ButtonPressMask  | ButtonReleaseMask;
      if((dpy = XOpenDisplay(NULL)) == NULL) {
          perror(argv[0]);
          exit(1);
      }
  dpy = XOpenDisplay(NULL);
  root = XDefaultRootWindow(dpy);
  
  int state;
  XWindowAttributes attributes;
  
  XGetInputFocus(dpy,&amp;root,&amp;state);
  printf("window id = %d\n"); 
  XSelectInput(dpy,root,event_mask);
  
  
  XEvent ev;
     while(1) {
  
  
        XNextEvent(dpy, &amp;ev);
      if(ev.type==ButtonRelease){
      printf("button release\n");
      }
  
        if (ev.type== KeyPress) {
      printf("keypress event\n");
        }
  
  
    }
  
   return 0;
  
  }
  </code></pre>