python-xlib question



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
.



Relevant Pages

  • python-xlib question
    ... I'm writing my first python script for Linux for a remote bluetooth ... I'm using python-xlib library to send keyboard and mouse events and at ... I can send keyboard emulated input to the window where pointer is on, ...
    (comp.lang.python)
  • Re: need help with python
    ... print "the salad is properly cooked." ... program, and then at the end of the program, CLOSES the window. ... From this command line, you can run your Python programs by ...
    (comp.lang.python)
  • Re: What other languages use the same data model as Python?
    ... but that's not what takes place at the level of Python ... In Pascal a pointer is a distinct data type, ... to sticking a reference in box a that points to obj. ... So how do you model cycles, including lists that contain ...
    (comp.lang.python)
  • Re: need help with python
    ... print "the salad is properly cooked." ... notepad then save and open with python... ... program, and then at the end of the program, CLOSES the window. ... From this command line, you can run your Python programs by ...
    (comp.lang.python)
  • Re: Help with PAM and ctypes
    ... addr is the memory address as a Python integer. ... the preferred way to create a NULL pointer in ctypes is to call the pointer type without an argument: ... My initial attempt to fix this involved wrapping strdup to allocate a ... copy of a string to send back to PAM. ...
    (comp.lang.python)