[BangPypers] moving/clicking the mouse cursor using python

Noufal Ibrahim noufal at gmail.com
Fri Jan 7 12:37:20 CET 2011

On Fri, Jan 07 2011, Narendra Sisodiya wrote:

> In my application, I need to move mouse-pointer and generate click
> event. I am not making any GUI application. mouse and click event will
> be trigger on dekstop.

Is this for some kind of testing? If so, the Linux Desktop Testing
Project might offer you something more robust - http://ldtp.freedesktop.org/


> Do anybody know better solution, I want to make a cross platform
> application.

Oooh. Windows too? X doesn't run there and so you'll have to resort to
something else. I did something like this using pyWin32
http://sourceforge.net/projects/pywin32/ but that was Windows only.

I'm not sure but you'll probably have to write multiple backends (for
windows and X anyway) and abstract them with a common layer - This might
be a useful project in general if you can architect it right. 

> I also found some way do it using C library like this
> from ctypes import cdll
> def move_mouse1(x,y):
>     dll = cdll.LoadLibrary('libX11.so')
>     d = dll.XOpenDisplay(None)
>     root = dll.XDefaultRootWindow(d)
>     dll.XWarpPointer(d,None,root,0,0,0,0,x,y)
>     dll.XCloseDisplay(d)
> But still i am searching for better way.. If anybody know, let me know

You might be able to use the Python bindings to Xlib to do this similar
to the way you did it using
ctypes - http://python-xlib.sourceforge.net/. 

This talks to the X directly and bypasses any C libraries. It's a pure
Python implementation and should work for any X implementation. Your
ctypes approach is limited to your platform.

It's not very actively maintained though.


More information about the BangPypers mailing list