473,666 Members | 2,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Di splay()

screen = display.screen( )
root = screen.root
pointer=root.qu ery_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.protoco l.event.ButtonP ress(**ev_d)
ev2=Xlib.protoc ol.event.Button Release(**ev2_d ict)

display.send_ev ent(Xlib.X.Poin terWindow,ev)

display.sync() # Send the inserted events
time.sleep(500/1000)
display.send_ev ent(Xlib.X.Poin terWindow,ev2)
display.sync()

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

Thanks to who wants help me
Bye,
Giovanni
Dec 16 '07 #1
1 4077
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.Di splay()
def mouse_click(but ton): #button= 1 left, 2 middle, 3 right
Xlib.ext.xtest. fake_input(disp lay,Xlib.X.Butt onPress, button)
display.sync()
Xlib.ext.xtest. fake_input(disp lay,Xlib.X.Butt onRelease,
button)
display.sync()

bye,
Giovanni
Dec 18 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
361
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 378 open ( +3) / 3298 closed (+34) / 3676 total (+37) Bugs : 886 open (-24) / 5926 closed (+75) / 6812 total (+51) RFE : 224 open ( +7) / 227 closed ( +7) / 451 total (+14) New / Reopened Patches ______________________
0
8445
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.