|
我用了xlib下的XSelectInput(display, RootWindow(display,screen_num), KeyPressMask | PointerMotionMask );但没有得到键盘和鼠标事件。以下是我一段代码,请教各位能人能不能帮我看出问题出在什么地方,谢谢!
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include <stdio.h>
Display *display;
int screen_num;
void main(int argc, char **argv)
{
Window rootWindow;
XEvent report;
char *display_name = NULL;
/* Connect to X server */
if ( (display=XOpenDisplay(display_name)) == NULL )
{
printf(" cannot connect to X server \n ");
exit (-1);
}
printf(" connect to X server \n");
screen_num=DefaultScreen(display);
while (1) {
rootWindow=RootWindow(display, screen_num);
XSelectInput(display,rootWindow,KeyPressMask | PointerMotionMask | FocusChangeMask);
XNextEvent(display, &report);
switch (report.type){
case MotionNotify:
printf("mouse move\n");
break;
case ButtonPress:
printf("Button press\n");
break;
case FocusOut:
printf("Focus out\n");
break;
case FocusIn:
printf("Focus in\n");
break;
}
}
请问捕捉rootwindow的鼠标和键盘事件是不是不用XSelectInput()函数呢,如何实现? |
|