Controlling mouse with Python
Tested on WinXP, Python 2.6 (3.x also tested) after installing pywin32 (pywin32-214.win32-py2.6.exe in my case):
import win32api, win32con
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
click(10,10)
How to control the mouse in Mac using Python?
I dug through the source code of Synergy to find the call that generates mouse events:
#include <ApplicationServices/ApplicationServices.h>
int to(int x, int y)
{
CGPoint newloc;
CGEventRef eventRef;
newloc.x = x;
newloc.y = y;
eventRef = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, newloc,
kCGMouseButtonCenter);
//Apparently, a bug in xcode requires this next line
CGEventSetType(eventRef, kCGEventMouseMoved);
CGEventPost(kCGSessionEventTap, eventRef);
CFRelease(eventRef);
return 0;
}
Now to write Python bindings!
Related Topics
Getting the Class Name of an Instance
Efficiently Using Multiple Numpy Slices for Random Image Cropping
Quoting Backslashes in Python String Literals
Using Os.Walk() to Recursively Traverse Directories in Python
In Python, How to Convert All of the Items in a List to Floats
How to Install Packages Using Pip According to the Requirements.Txt File from a Local Directory
Display a Decimal in Scientific Notation
What Are the 'Levels', 'Keys', and Names Arguments for in Pandas' Concat Function
How to Extract the N-Th Elements from a List of Tuples
Create a Directly-Executable Cross-Platform Gui App Using Python
How to Upgrade All Python Packages with Pip
Using Lambda Expression to Connect Slots in Pyqt
Non-Alphanumeric List Order from Os.Listdir()
Replace Non-Ascii Characters with a Single Space
How to Check If the String Is Empty