Advertisement
jckuri

MacMouseRobot.py

Jul 11th, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. # python MacMouseRobot.py
  2. # http://pythonhosted.org/pyobjc/install.html
  3. import time
  4. from Quartz.CoreGraphics import CGEventCreateMouseEvent
  5. from Quartz.CoreGraphics import CGEventPost
  6. from Quartz.CoreGraphics import kCGEventMouseMoved
  7. from Quartz.CoreGraphics import kCGEventLeftMouseDown
  8. from Quartz.CoreGraphics import kCGEventLeftMouseDown
  9. from Quartz.CoreGraphics import kCGEventLeftMouseUp
  10. from Quartz.CoreGraphics import kCGMouseButtonLeft
  11. from Quartz.CoreGraphics import kCGHIDEventTap
  12.  
  13. def mouseEvent(type, posx, posy):
  14.   theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
  15.   CGEventPost(kCGHIDEventTap, theEvent)
  16.  
  17. def mousemove(posx,posy):
  18.   mouseEvent(kCGEventMouseMoved, posx,posy);
  19.  
  20. def mouseclick(posx,posy):
  21.   #uncomment this line if you want to force the mouse to MOVE to the click location first (i found it was not necesary).
  22.   #mouseEvent(kCGEventMouseMoved, posx,posy);
  23.   mouseEvent(kCGEventLeftMouseDown, posx,posy);
  24.   mouseEvent(kCGEventLeftMouseUp, posx,posy);
  25.  
  26. print("Mac Mouse")
  27. mouseclick(0,0);
  28. mousemove(100,100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement