Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

A quick pull together of a mouse controller via python for Apple. NB: Find the slowly updated version at https://github.com/willwade/MacroServerMac/blob/master/AppleUIEvents.py

View AppleUIEvents.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
## The following is from TonyT
## http://hints.macworld.com/article.php?story=2008051406323031
 
import sys
import time
from Quartz.CoreGraphics import * # imports all of the top-level symbols in the module
 
class AppleMouseEvents():
"""
with thanks to:
TonyT http://hints.macworld.com/article.php?story=2008051406323031
example:
m = AppleMouseEvents()
pos = m.currentPos()
m.mousedrag(pos.x,pos.y+float('30'))
"""
def __init__(self):
self.relative = True
def mouseEvent(self,type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(self,posx,posy):
self.mouseEvent(kCGEventMouseMoved, posx,posy);
def mouseclickdn(self,posx,posy):
self.mouseEvent(kCGEventLeftMouseDown, posx,posy);
def mouseclickup(self,posx,posy):
self.mouseEvent(kCGEventLeftMouseUp, posx,posy);
def mousedrag(self,posx,posy):
self.mouseEvent(kCGEventLeftMouseDragged, posx,posy);
def mouserclick(self,posx,posy):
self.mouseEvent(kCGEventRightMouseDown, posx,posy);
self.mouseEvent(kCGEventRightMouseUp, posx,posy);
def mousesingleclick(self,posx,posy):
self.mouseclickdn(posx,posy)
self.mouseclickup(posx,posy)
 
def mousedblclick(self,posx,posy):
self.mousesingleclick(posx,posy)
self.mousesingleclick(posx,posy)
def mousetrplclick(self,posx,posy):
self.mousesingleclick(posx,posy)
self.mousesingleclick(posx,posy)
self.mousesingleclick(posx,posy)
def currentPos(self):
ourEvent = CGEventCreate(None);
return CGEventGetLocation(ourEvent); # Save current mouse position
 
class AppleKeyboardEvents():
def __init__(self):
self.relative = True
 
class AppleWindowEvents():
def __init__(self):
self.relative = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.