It looks like you're only catching events from the root window; if I run your code and click on the desktop, it actually does something:

Traceback (most recent call last):
  File "mousepos.py", line 16, in <module>
    main()
  File "mousepos.py", line 12, in main
    print event.query_pointer()._data
  File "/usr/lib/python2.7/site-packages/Xlib/protocol/rq.py", line 1369, in __getattr__
    raise AttributeError(attr)
AttributeError: query_pointer

If I change the print line to `print event._data`, it works.

If you want to catch events from all windows intsead of just the root window, you'll probably have to change the event filter, if I remember correctly. You'll probably need to look at the documentation for Xlib (http://tronche.com/gui/x/xlib/) and see what it says; it should be pretty straightforward to translate that to Python, since python-xlib tries to keep the API pretty close to the standard Xlib interface.


2011/12/15 阮铮 <rz1991@foxmail.com>
Hi,

I am new to Xlib and tries to write a small scripts to response my mouse click in screen and return the position value. It seems not work. Since I can hardly find any friendly tutorial about the python-xlib, I hope some of you in the mailing list could help me. The question is rather simple.

My code is like this:


import Xlib
import Xlib.display

def main():
    display = Xlib.display.Display()
    root = display.screen().root
    root.change_attributes(event_mask=
			Xlib.X.ButtonPressMask |
			Xlib.X.ButtonReleaseMask |
			)
    while True:
        event = root.display.next_event()
        print event.query_pointer()._data
if __name__ == "__main__":
    main()

Thank you very much!

------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for
developers. It will provide a great way to learn Windows Azure and what it
provides. You can attend the event by watching it streamed LIVE online.
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
python-xlib-users mailing list
python-xlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/python-xlib-users