#!/usr/bin/env python # -*- coding: iso-8859-15 -*- import time import Image import LtMacroAPI import sys import random import os pid = str(os.getpid()) pidfile = open("./ltmacros/running.pid", 'w') pidfile.write(pid) pidfile.close() ########################################################## # USAGE: # automatic mining task # Pin XM*YM windows, starting from upper left corner. # Run this macro and clic on the action in the menu # macro then keep clic, wait for TIMER to disapear and so on # Mostly inspired from SlatePicker ########################################################## ########################################################## # constants : # I determined that approximative position of "END" is dx = 75 # from right of window (25 for 1st icon, 75 for the 2nd icon from right, 50 pixels/icon) dy = 115 # from top # size of mining menu omw = 265 omh = 200 # size of menus array xm = 2 ym = 2 ########################################################## # Program : # Tell me where to click in the first pinned menu # get the coords of the mouseclick ((window, relative x, relative y), (root window, absolute screen x, absolute screen y)) # mine windows, mine x, mine y ((mw, mx,my), root_hit) = LtMacroAPI.getwindowclick() # Get Window attributes (attr.width, attr.height) attr =mw.get_geometry() # Now we know where to watch for "TIMER" disappearing : watchX = attr.width-dx watchY = dy state = 1 # initial click to get "END" picture try: LtMacroAPI.clickwindow((mw,mx,my)) # click it except LtMacroAPI.GrabFailed: print "**** can't do initial clic (user interacting?), dying .." raise # little pause to let "END" picture appear time.sleep(1) i1 = LtMacroAPI.getimage(mw, watchX, watchY, 5, 5) while True: # check the 10x10 image patch we selected above try: i2 = LtMacroAPI.getimage(mw, watchX, watchY, 5, 5) except LtMacroAPI.GetImageFailed: print "window went out of view, could survive this easily, but more fun to die ;)" raise # if the image patch is identical to our stored one, we should click it if((state==1) and (not LtMacroAPI.compare_raw_images(i1, i2))): state=2 print " - hit!" # choisissons un menu au hasard.. rx=random.randint(0,xm-1) ry=random.randint(0,ym-1) cx=(rx*omw)+mx cy=(ry*omh)+my print 'chosen menu (', rx , ';' , ry , ')' try: LtMacroAPI.clickwindow((mw,cx,cy)) # click it except LtMacroAPI.GrabFailed: state=1 print "**** can't grab mouse (user interacting?), aborting this hit" time.sleep(1) # leave a time gap so we don't hammer the slate button repeatedly until ATITD notices elif((state==2) and (LtMacroAPI.compare_raw_images(i1, i2))): print "icon has reappared..ok!" state=1 time.sleep(0.1) # 100ms pause so we don't eat all the CPU 265, 65