Hi. I want to write a program using Xlib to monitor user activities including mouse and keyboard. I wrote the program. The strange thing is it only monitor part of the events.
I used XSelectInput to monitor several types of event. But only SubstructureNotifyMask events are displayed. Can anyone please help me why?? I can't realy figure it out.
Thanks in advance!!!
Code:
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h> /* getenv(), etc. */
#include <unistd.h> /* sleep(), etc. */
int main(int argc, char* argv[]) {
Display* display; /* pointer to X Display structure. */
int screen_num; /* number of screen to place the window on. */
char *display_name = getenv("DISPLAY"); /* address of the X display. */
XEvent an_event;
Window root_window;
unsigned long events;
XWindowAttributes attrs;
static int count = 0;
display = XOpenDisplay(display_name);
if (display == NULL) {
fprintf(stderr, "%s: cannot connect to X server '%s'\n",
argv[0], display_name);
exit(1);
}
screen_num = DefaultScreen(display);
root_window = RootWindow(display, screen_num);
XSync(display, False);
XGetWindowAttributes (display, root_window, &attrs);
XSelectInput(display, root_window, SubstructureNotifyMask | PointerMotionMask | KeyPressMask);
while(1) {
XNextEvent(display, &an_event);
switch(an_event.type) {
case Expose:
//printf("called Expose event(%d)\n", count);
break;
default:
//printf("called default(%d)\n", count);
break;
}
printf("event.type: %d, (%d)\n", an_event.type, count);
count++;
}
/* close the connection to the X server. */
XCloseDisplay(display);
return 0;
}