LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-23-2010, 02:09 AM   #1
hamedhsn
Member
 
Registered: Feb 2010
Distribution: opensuse 11.2
Posts: 57

Rep: Reputation: 0
some keyboard/mouse events cant be caught-xlib programming


hi ..
i have a problem with this program ,it lists the current window along with window id thet are running on the system,result is that for a particular window id that i enter i got odd result:
for application like firefox or gedit just motion notify event works,non of the other events work??
for my terminal(bash) everything works,key press,keyrelease,mouse notify,mouserelease,...
i dont know why??

//this part get the window id
Code:
Display * dis;
   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];
                        XSelectInput (dis, w, KeyPressMask |PointerMotionMask |ButtonReleaseMask);
                        char* name = '\0';
                        status = XFetchName(dis, w, &name);
                        if (status >= Success)
                        {
                                printf("Found: %u  %s\n", w, name);
                         }
                        XFree(name);
    
                }
                XFree(data);
        }
//Event handling for windows

Code:
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(stdout,"middle left click");
                if (event.xbutton.button==3)
                    fprintf(stdout,"mouse right click");
            break;                
            
        }
    }
}

Last edited by hamedhsn; 09-28-2010 at 02:17 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Xlib mouse events and ButtonPressMask abhinav.zoso Programming 1 11-27-2009 06:16 AM
Keyboard events interrupting mouse events. miner49er Linux - Hardware 3 11-04-2008 04:16 AM
Mouse interrupting keyboard events, can't type while mouse is moving sandaili Linux - Hardware 0 08-04-2008 06:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration