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.
Any idea how can i do it?
The code snippet is as follows:
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
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,&root,&state);
printf("window id = %d\n");
XSelectInput(dpy,root,event_mask);
XEvent ev;
while(1) {
XNextEvent(dpy, &ev);
if(ev.type==ButtonRelease){
printf("button release\n");
}
if (ev.type== KeyPress) {
printf("keypress event\n");
}
}
return 0;
}