Skip to content

Instantly share code, notes, and snippets.

@EliseAv
Last active September 20, 2015 03:52
Show Gist options
  • Save EliseAv/58d8ca88e4e1a4055cc0 to your computer and use it in GitHub Desktop.
Save EliseAv/58d8ca88e4e1a4055cc0 to your computer and use it in GitHub Desktop.
Beat Luna in “Banned From Equestria Daily” (by pokehidden) on your Mac. :P
#!/usr/bin/python
# -*- coding: utf-8 -*-
from random import random
from sys import argv, exit
from time import sleep
from Quartz.CoreGraphics import CGEventCreateMouseEvent, kCGMouseButtonLeft, CGEventPost, kCGHIDEventTap, kCGEventMouseMoved, kCGEventLeftMouseDown, kCGEventLeftMouseUp, CGEventCreate, CGEventGetLocation
from Quartz import NSResponder
def fight_luna(attack):
try:
x = 850
while True:
for i in range(7):
sleep(0.05)
attack(x, 750)
attack(x, 250)
except KeyboardInterrupt:
exit(0)
def main():
if 'o' in argv:
fight_luna(mousemove)
elif 'a' in argv:
fight_luna(mouseclick)
elif 'x' in argv:
subscribe_keyboard()
else:
test()
def subscribe_keyboard():
the_event = CGEventCreateKeyboardEvent(None, key_code, True)
def mouse_event(evtype, posx, posy):
the_event = CGEventCreateMouseEvent(None, evtype, (posx, posy), kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, the_event)
def mousemove(posx, posy):
mouse_event(kCGEventMouseMoved, posx, posy)
def mouseclick(posx, posy):
mouse_event(kCGEventLeftMouseDown, posx, posy)
mouse_event(kCGEventLeftMouseUp, posx, posy)
def test():
our_event = CGEventCreate(None)
# Save current mouse position
currentpos = CGEventGetLocation(our_event)
# Click the "Apple"
mouseclick(25, 5)
# Restore mouse position
mousemove(int(currentpos.x), int(currentpos.y))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment