#!/usr/bin/env python import time import Image import LtMacroAPI import os pid = str(os.getpid()) pidfile = open("./ltmacros/running.pid", 'w') pidfile.write(pid) pidfile.close() ########################################################## #USAGE: # resource (slate, grass, clay) picker #stand on slate/grass and start macro and click on the button when mousepointer changes to + #this program will keep scanning that exact location for an exact match of a 10x10 patch there #if it sees one, it will click it # will try others positions on the left too (icon wide) ########################################################## # get the coords of a mouseclick ((window, relative x, relative y), (root window, absolute screen x, absolute screen y)) (target_hit, root_hit) = LtMacroAPI.getwindowclick() # store a 10x10 image of the pixels where the mouse was clicked (hopefully the slate button) i1 = LtMacroAPI.getimage(target_hit[0], target_hit[1], target_hit[2], 10, 10) # size of a standard action icon 64x100 # size of the "what to do now" icon 134x100 state = 1 # loop forever while True: missed = True # check the 10x10 image patch we selected above try: i2 = LtMacroAPI.getimage(target_hit[0], target_hit[1], target_hit[2], 10, 10) 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 LtMacroAPI.compare_raw_images(i1, i2): missed=False if(state==1): state = 2 print " - hit!" try: LtMacroAPI.clickwindow(target_hit) # click it except LtMacroAPI.GrabFailed: print "**** can't grab mouse (user interacting?), aborting this hit" state = 1 if((state==2) and (missed==True)): print "icon has disaperead ; ok" state=1 time.sleep(0.1) # 100ms pause so we don't eat all the CPU