471,313 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,313 software developers and data experts.

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
Dec 16 '07 #1
1 3909
Solved,

I solved using Xtest fake_input, hoping helping other people i post
the code:

#!/usr/bin/env python
import Xlib.display
import Xlib.X
import Xlib.XK
import Xlib.error
import Xlib.ext.xtest

display = Xlib.display.Display()
def mouse_click(button): #button= 1 left, 2 middle, 3 right
Xlib.ext.xtest.fake_input(display,Xlib.X.ButtonPre ss, button)
display.sync()
Xlib.ext.xtest.fake_input(display,Xlib.X.ButtonRel ease,
button)
display.sync()

bye,
Giovanni
Dec 18 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.