python-xlib question

giovanni.iovino at gmail.com giovanni.iovino at gmail.com
Sun Dec 16 06:33:10 EST 2007


Hi,
sorry for my English.
I'm writing my first python script for Linux for a remote bluetooth
application.
I'm using python-xlib library to send keyboard and mouse events and at
the moment
I can send keyboard emulated input to the window where pointer is on,
i can also move the pointer over the
desktop.
I'm using python 2.5 on a Ubuntu 7.10 system with gnome and compiz
However the method fails when i try to emulate mouse clicks
Here follows  the code I'm using, if you change ButtonPress and
ButtonRelease with KeyPress and KeyRelease and change the detail of
ev_d it works
####################################################################################
#!/usr/bin/env python

import Xlib.display
import Xlib.X
import Xlib.XK
import Xlib.error
import time

display = Xlib.display.Display()

screen = display.screen()
root = screen.root
pointer=root.query_pointer() #Get info like window where pointer is on
and pointer position
window=pointer.child

ev_d = dict(
                time = 0, # Time of the event (useful for double-
clicks for mouse
events)
                root = root,
                window = pointer.child, #The window where is the
pointer
                same_screen = 1,
                child = Xlib.X.NONE,
                root_x = pointer.root_x,
                root_y = pointer.root_y,
                event_x = pointer.win_x,
                event_y = pointer.win_y,
                state = Xlib.X.NONE,
                detail =Xlib.X.Button1
        )

ev2_dict = ev_d.copy()
ev2_dict['state'] = Xlib.X.Button1 << 8 # that is ButtonXMask
ev=Xlib.protocol.event.ButtonPress(**ev_d)
ev2=Xlib.protocol.event.ButtonRelease(**ev2_dict)

display.send_event(Xlib.X.PointerWindow,ev)

display.sync() # Send the inserted events
time.sleep(500/1000)
display.send_event(Xlib.X.PointerWindow,ev2)
display.sync()

#################################################################

Thanks to who wants help me
Bye,
Giovanni



More information about the Python-list mailing list