Thursday, January 27, 2011

Simulating mouse click on Snow Leopard

After googling for 1 hour i came up with the following python script.

import sys
import time
from Quartz import *

def createMouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, theEvent)

if __name__ == '__main__':
x = int(sys.argv[1])
y = int(sys.argv[2])

createMouseEvent(kCGEventLeftMouseDown, x, y);
createMouseEvent(kCGEventLeftMouseUp, x, y);

Usage: python 100 100
It'll move the mouse to (100, 100)

Here is the same script on github.

I used the following sources
metapep's blogpost
pepijndevos's PyMouse
GeekOrgy's Python script
a stackoverflow entry


1 comment:

  1. Laser Galvo is also named as lase scanners, which are popular in the laser manufacturing industry.