开发者

some keyboard/mouse events cant be caught-xlib programming

I have a problem with this program. It lists the current windows along with their window IDs, that are running on the system.

Result is that for a particular window ID that i entered, I got an odd result: for applications like firefox or gedit, just the motion notify event works, non of the other events work.

For my terminal (bash), everything works: key press, key release, mouse notify, mouse release, ...

Why is this the case?

Display * dis;
Window w;
dis = XOpenDisplay (0);
w=XDefaultRootWindow(dis);
Atom a = XInternAtom(dis, "_NET_CLIENT_LIST" , 1);
Atom actualType;
int format;
unsigned long numItems, bytesAfter;
unsigned char *data =0;
int status = XGetWindowProperty(dis,
                                w,
                                a,
                                0L,
                                (~0L),
                                0,
                                AnyPropertyType,
                                &actualType,
                                &format,
                                &numItems,
                                &bytesAfter,
                                &data);

if (status >= Success && numItems)
{
    int *array = (int*) data;
    int k;
    for (k = 0; k < numItems; k++)
    {
         // get window Id:
         Window w = (Window) array[k];
         char* name = '\0';
         status = XFetchName(dis, w, &name);
         if (status >= Success)
         {
             XSelectInput (dis, wev, KeyPressMask |PointerMotionMask |ButtonReleaseMask);
             printf("Found: %u  %s\n", w, name);
         }
         XFree(name);
    }
    XFree(data);
}
XEvent event;
while (1) {
    XNextEvent(dis, &event);
    switch  (event.type) {

        //MOUSE LOCATION
        case MotionNotify:
            fprintf(stdout,"x: %d y:%d\n",event.xmotion.x,event.xmotion.y);
        break;    
        //--------------------------------

        //KEYBOARD KEY(it does not wok)        
        case KeyPress:
             fprintf(stdout,"key: %d \n",event.xkey.keycode);
        break;
        //--------------------------------

        //KEYBOARD KEY(it does not wok)        
        case KeyRelease:
             fprintf(stdout,"key: %d \n",event.xkey.keycode);
        break;
        //--------------------------------

        case ButtonRelease:
            //show which button is released
            if (event.xbutton.button==1)
                fprintf(stdout,"mouse left click");
            if (event.xbutton.button==2)
                fprintf(stdou开发者_如何转开发t,"middle left click");
            if (event.xbutton.button==3)
                fprintf(stdout,"mouse right click");
        break;                

    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜