dogtail is a GUI test tool and automation framework written in Python. It uses Accessibility (a11y) technologies to communicate with desktop applications. dogtail scripts are written in Python and executed like any other Python program.
https://fedorahosted.org/dogtail/
http://stackoverflow.com/questions/1946181/how-can-i-control-the-keyboard-and-mouse-with-python