Advertisement
Guest User

beatthecolorgame

a guest
Sep 23rd, 2014
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. from win32api import *
  2. from win32gui import *
  3. import win32con
  4. import time
  5. import pythoncom
  6. import win32gui
  7. from PIL import Image
  8. import pyHook
  9.  
  10. global start
  11. global size
  12. start = False
  13. size = None
  14.  
  15. def callback(event):
  16.     print('asdf')
  17.     global size
  18.     global start
  19.     size = int(event.Key)
  20.     start = True
  21.     return True
  22.  
  23.  
  24.  
  25. def grab(bbox = None):
  26.     size, data = grabber()
  27.     im = Image.frombytes("RGB", size, data, "raw", "BGR", (size[0]*3 + 3) & -4, -1)
  28.     if bbox:
  29.         im = im.crop(bbox)
  30.     return im
  31.  
  32. def difcolor(image, size):
  33.  
  34.     (x, y) = image.size
  35.     print(x, y)
  36.     diff = 500//size
  37.     summa = [0, 0, 0]
  38.     colors = [[None for i in range(0,470,diff)] for j in range(0,470,diff)]
  39.     poss = [[(560+i,250+j) for i in range(0,470,diff)] for j in range(0,470,diff)]
  40.  
  41.     print(colors)
  42.    
  43.     for i in range(0, size):
  44.         for j in range(0, size):
  45.             colors[i][j] = image.getpixel((560+diff*j, 250+diff*i))
  46.  
  47.  
  48.     print(colors)
  49.  
  50.     colorlist = []
  51.     for row in colors:
  52.         colorlist.extend(row)
  53.     test = False
  54.     for element in colorlist:
  55.         if colorlist.count(element) == 1:
  56.             pos = colorlist.index(element)
  57.             test = True
  58.     if test:
  59.         xpos = pos//size
  60.         ypos = pos % size
  61.         SetCursorPos(poss[xpos][ypos])
  62.         mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
  63.         mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
  64.  
  65.  
  66. grabber = Image.core.grabscreen
  67.  
  68. hook = pyHook.HookManager()
  69. hook.KeyDown = callback
  70. hook.HookKeyboard()
  71.  
  72. while True:
  73.  
  74.     while not start:
  75.         pythoncom.PumpWaitingMessages()
  76.     start = False
  77.     image = grab()
  78.    
  79.     anomaly = difcolor(image, size)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement