On 16.12.2011 05:55, 阮铮 wrote:
Hi,
A question about Xlib Library in Python troubled me for several days
and I finally found this email list. I hope someone could answer my
question. I think it is easy for experienced user.
I would like to write a small script to response my mouse click in
root screen and write something in the terminal. My script is like
this, but it does not work in my computer.
from Xlib import X
import Xlib.display
def main():
display = Xlib.display.Display()
root = display.screen().root
root.change_attributes(event_mask=
X.ButtonPressMask |
X.ButtonReleaseMask)
while True:
event = root.display.next_event()
print "1"
if __name__ == "__main__":
main()
Any hints are welcome
Thank you!
Ruan zheng
You haven't said *how* your script is not working and what
distro/desktop-environment you use, but I suspect, that your script
collides with the window manager.
Most window managers occupy the root window for them self, and even
display another window above the root window (for the wallpaper, the
desktop icons, etc.), so your clicks never reach the root window,
but whatever the window manager draws as the background.
If you run your script in a plain and naked X "session" with nothing
but an xterm *and no window manager*, your script will probably work.
--
http://mail.python.org/mailman/listinfo/python-list