[BangPypers] moving/clicking the mouse cursor using python

Narendra Sisodiya narendra at narendrasisodiya.com
Fri Jan 7 12:06:10 CET 2011

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
Quick and dirty way to do this

import os
def move_mouse(x,y):
    os.system('xdotool mousemove ' + str(x) + ' ' + str(y))
def leftclick():
    os.system('xdotool click 1')
def rightclick():
    os.system('xdotool click 3')

Do anybody know better solution, I want to make a cross platform
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)

But still i am searching for better way.. If anybody know, let me know

│    Narendra Sisodiya
│    http://narendrasisodiya.com

More information about the BangPypers mailing list