Skip to content

Instantly share code, notes, and snippets.

@lancepioch
Created September 2, 2014 14:06
Show Gist options
  • Save lancepioch/56e5921c9d52617d4759 to your computer and use it in GitHub Desktop.
Save lancepioch/56e5921c9d52617d4759 to your computer and use it in GitHub Desktop.
Micromanage Python Script - http://pastebin.com/J86M3vYb
#!/usr/bin/env python2
from PIL import Image
from PIL.ImageStat import Stat
from time import sleep
from Xlib import X
from Xlib.display import Display
from Xlib.ext.xtest import fake_input
from Xlib.X import ZPixmap
class Mouse:
def __init__(self):
self.display = Display()
self.root = self.display.screen().root
def refresh(self):
self.display.sync()
def get_pos(self):
data = self.root.query_pointer()._data
return data["root_x"], data["root_y"]
def get_colour(self):
x, y = self.get_pos()
image = self.root.get_image(x, y, 1, 1, ZPixmap, 0xffffffff)
image_rgb = Image.fromstring("RGB", (1, 1), image.data, "raw", "BGRX")
return tuple(map(int, Stat(image_rgb).mean))
def is_red(self):
return mouse.get_colour()[2] == 0
def move(self, x, y):
self.root.warp_pointer(x, y)
self.refresh()
def down(self):
fake_input(self.display, X.ButtonPress, 1)
self.refresh()
def up(self):
fake_input(self.display, X.ButtonRelease, 1)
self.refresh()
def charge(self):
self.down()
while not self.is_red():
pass
self.up()
mouse = Mouse()
base = 297
spacing = 110
head, tail = 241, 410
right = 305
while True:
for i in range(0, 5):
mouse.move(head, base + spacing*i)
while mouse.is_red():
pass
mouse.move(tail, base + spacing*i)
mouse.charge()
sleep(0.1)
for i in range(0, 5):
mouse.move(head + right, base + spacing*i)
while mouse.is_red():
pass
mouse.move(tail + right, base + spacing*i)
mouse.charge()
sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment