def findTarget(img): template_tg = cv2.imread('template_target2.png', 0) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) ret,th1 = cv2.threshold(gray,253,255,cv2.THRESH_TOZERO_INV) ret,th3 = cv2.threshold(th1,251,255,cv2.THRESH_BINARY) kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (20, 15)) closed = cv2.morphologyEx(th3, cv2.MORPH_CLOSE, kernel) closed = cv2.erode(closed, None, iterations = 3) closed = cv2.dilate(closed, None, iterations = 2) (cnts, hierarchy) = cv2.findContours(closed,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) approxes = [] hulls = [] for cnt in cnts: approxes.append(cv2.approxPolyDP(cnt,0.01*cv2.arcLength(cnt,True),True)) hulls.append(cv2.convexHull(cnt)) left = list(cnt[cnt[:,:,0].argmin()][0]) right = list(cnt[cnt[:,:,0].argmax()][0]) print 'left x' + str(left[0])+ 'y '+ str(left[1]) print 'right x' + str(right[0])+ 'y '+ str(right[1]) center = round((right[0]+left[0])/2) center = int(center) moveMouse(center-10,left[1]+70) if (findFromTargeted(template_tg, left, right)): autoit.mouse_click('left', center-10, left[1]+70) return True pyautogui.moveTo(center,left[1]+70) moveMouse(center,left[1]+70) if (findFromTargeted(template_tg, left, right)): autoit.mouse_click('left', center+10, left[1]+70) return True
def extract_rr(filename): pid = autoit.run("C:/Program Files/Kubios/Kubios HRV Standard/kubioshrv.exe") # wait until screen is loaded assert autoit.win_wait_active(f"[TITLE:{kubios_title}]", 30) time.sleep(0.25) # get position and click menu->open x, y, _, _ = autoit.win_get_pos(f"[TITLE:{kubios_title}]") assert autoit.mouse_click(x=x+20, y=y+50, speed=10) time.sleep(0.5) assert autoit.mouse_click(x=x+20, y=y+70, speed=10) # wait for loading of file input screen assert autoit.win_wait_active(f"[TITLE:{title_open}]", 30) time.sleep(0.25) assert autoit.control_send(f"[TITLE:{title_open}]", "[CLASS:Edit]", filename) time.sleep(0.25) assert autoit.control_click(f"[TITLE:{title_open}]", "[CLASS:Button; INSTANCE:1]") time.sleep(1) # check if there was an error (if Open Data File is still there) assert not autoit.win_active(f"[TITLE:{title_open}]"), 'Failed to load!' assert os.system(f"taskkill /PID {pid} /F")==0
def update(): game_window = WindowMgr() game_window.find_window_wildcard(gameWildcard) quest_pos = autoit.mouse_get_pos() print(quest_pos) print(game_window.handle) print("\nHold {} to stop.".format(stopShortcut)) while True: try: prev_mouse_pos = autoit.mouse_get_pos() prev_foreground_window = WindowMgr() prev_foreground_window.foreground_window() game_window.set_foreground() time.sleep(0.040) autoit.mouse_click("left", quest_pos[0], quest_pos[1], 1, 0) prev_foreground_window.set_foreground() autoit.mouse_move(prev_mouse_pos[0], prev_mouse_pos[1], 0) for i in range(clickInterval): if keyboard.is_pressed(stopShortcut): return time.sleep(1) except: continue
def left_click(coords): title = window.focus_bdo() autoit.mouse_click(button="left", x=coords[0], y=coords[1], clicks=2, speed=20)
def startFromMenu(): # 게임이 종료되고 메뉴로 나가진 상황에서 다시 시작 global reset_flag win_pos = getWinPos() x = win_pos['left'] y = win_pos['top'] autoit.mouse_click("left", x + START_X, y + START_Y, 1) reset_flag = True
def add_data_shp(): #加载矢量数据shp格式 autoit.mouse_click("left",120,92,1) #点击加载矢量数据 autoit.win_wait_active(u"打开矢量文件",15) autoit.control_set_text(u"打开矢量文件","Edit1",r"C:\Users\admin\Desktop\PIEDATA\Lambert_SHP\beijing.shp") autoit.control_click(u"打开矢量文件","Button1") #选择好文件,点击打开 autoit.win_wait_active(u"提示",5) #不同坐标系,提示是否新建图层 autoit.control_click(u"提示","Button2") #新建图层 sleep(5)
def click1(cls, title, text, x, y, button="", clicks=1): """ :description 执行鼠标点击操作 :return: """ # 使用相对坐标的情况 pos = autoit.win_get_pos(title, text=text) autoit.mouse_click(button, x + pos[0], y + pos[1], clicks=clicks)
def manualReset(): # 게임 중 reset global reset_flag print("manual reset") PressAndRelease(ESCAPE, 0.1) win_pos = getWinPos() x = win_pos['left'] y = win_pos['top'] autoit.mouse_click("left", x + RESET_X, y + RESET_Y, 1) reset_flag = True
def add_data_jpg(): #加载栅格数据jpg格式 '''添加数据方法一:设置焦点进行传参,添加jpg数据''' autoit.mouse_click("left",54,92,1) #点击加载栅格数据 autoit.win_wait_active(u"打开栅格文件",15) #等待窗口活跃,15秒超时 autoit.control_focus(u"打开栅格文件", "[Class:Edit; instance:1]") #设置焦点 autoit.control_set_text(u"打开栅格文件", "[Class:Edit; instance:1]","C:\Users\Administrator\Desktop\GF1.jpg") # 输入文本 autoit.control_click(u"打开栅格文件", "Button1") sleep(5)
def right_click_native(self, window_name, x, y): """ Click the left mouse button on a screen location Example: | Left Click Native | 320 | 240 | """ logger.debug("Setting native cursor position to {0},{1}".format(x, y)) logger.debug("Clicking right button") left, top, right, bottom = autoit.win_get_pos(window_name) autoit.mouse_move(left + x, top + y) autoit.mouse_click(button="right", x=left + x, y=top + y)
def equiping(row): # check already equipped equip_y = Equip_Icon_Start_y + row * Equip_Icon_Gap + 30 # btn offset equip_btn_x = 463 if not IsColorAtCoord(equip_btn_x, equip_y, check_color=0x58aa3d): bottomMenuExit() return # equip autoit.mouse_click('left', equip_btn_x, equip_y, 1, 10)
def right_control(): # 图层右键功能 autoit.mouse_click("Right", 93, 193, 1, 10) # 右键点击图层,打开功能列表 sleep(1) autoit.send("{down 10}") # 选择第十行,选择属性 sleep(1) autoit.send("{enter}") autoit.win_wait_active(u"图层属性", 5) # 等待图层属性窗口,5秒超时 sleep(1) autoit.control_click(u"图层属性", "Button2") # 关闭图层属性 sleep(1)
def add_data_tif(): # 加载栅格数据Tif格式,此格式是否需要建立金字塔 '''添加数据方法二:直接使用control_set_text传参,添加tif数据是否建立金字塔''' autoit.mouse_click("left", 50, 92, 1) # 点击加载栅格数据 autoit.win_wait_active(u"打开栅格文件", 15) autoit.control_set_text(u"打开栅格文件", "Edit1", r"C:\Users\admin\Desktop\PIEDATA\GF1.tiff") autoit.control_click(u"打开栅格文件", "Button1") # 确定打开文件 autoit.win_wait_active(u"建立金字塔", 5) # 等待是否建立金字塔窗口 autoit.control_click(u"建立金字塔", "Button3") # 取消建立金字塔 sleep(10) '''添加数据方法三:使用control_send传参,添加tif数据是否建立金字塔'''
def temp_move(win): # случайное перемещение и возврат назад x = 954 y = 485 dx = random.randint(50, 200) dy = random.randint(-200, 200) if autoit.win_wait_active(win): time.sleep(0.5) autoit.mouse_click("left", x + dx, y + dy) t = random.randint(1, 3) time.sleep(t) autoit.mouse_click("left", x - dx, y - dy) time.sleep(1)
def wait_for_fish(): global fish, x, x1, x2, y1, y2, image for y in range(y1, y2): for x in range(x1, x2): color = image.getpixel((x, y)) if color == (68, 252, 234): autoit.mouse_click('left') image = ImageGrab.grab() fish = True break if fish: break
def click(self, title, text, x, y, button="main", clicks=1): """鼠标点击""" pos = autoit.win_get_pos(title, text=text) ''' win_get_pos()为获取指定窗口的坐标位置和大小 [0]X坐标 [1]Y坐标 [2]宽度 [3]高度 ''' #autoit.mouse_click(button, x + pos[0], y + pos[1], clicks=clicks) autoit.mouse_click(button, x, y, clicks=clicks)
def posionDaggerAtOnce(): daggers = [(177, 432), (220, 445), (260, 450), (303, 450), (343, 445), (386, 432)] # 177, 427 # d = daggers[0] # if not isThereDagger(d[0], d[1]): # return # dagger color 4d7f24, 4a 84 29 # click all dagger quickly for d in daggers: autoit.mouse_click('left', d[0], d[1], 3, 3)
def findTarget(self): img = self.getScreen(self.leftCornerx,self.leftCornery,self.x2,self.y2) cv2.rectangle(img, (582, 407), (1100, 750), [0, 0, 0], -1) cv2.rectangle(img, (0, 0), (520, 77), [0, 0, 0], -1) # cv2.imshow("images", img) # cv2.waitKey(0) # bla() colorMin = [255, 131, 86] colorMax = [255, 167, 108] mask = cv2.inRange(img, array(colorMin, dtype='uint8'), array(colorMax, dtype='uint8')) mask = cv2.filter2D(mask,-1, ones((5,5), float32)) (cnts, hierarchy) = cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) colorMin = [166, 228, 154] colorMax = [169, 232, 156] mask = cv2.inRange(img, array(colorMin, dtype='uint8'), array(colorMax, dtype='uint8')) mask = cv2.filter2D(mask,-1, ones((15,15), float32)) (cnts, hierarchy) = cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) cnts = sorted(cnts, key=lambda cnt: self.contourHeight(cnt), reverse=True); # cv2.drawContours(img, cnts, -1, (255,0,0), 3) # cv2.imshow("images", img) # cv2.waitKey(0) # bla() for cnt in cnts: x,y,w,h = cv2.boundingRect(cnt) left = list(cnt[cnt[:,:,0].argmin()][0]) right = list(cnt[cnt[:,:,0].argmax()][0]) print 'left x' + str(left[0])+ 'y '+ str(left[1]) print 'right x' + str(right[0])+ 'y '+ str(right[1]) if right[0] - left[0] < 20: print 'Small diff ' + str(right[0] - left[0]) continue x,y,w,h = cv2.boundingRect(cnt) test = self.getScreen(x,y+h,x+w,y+200) cv2.imwrite('tgt/' + str(int(time.time())) + '_not_chmp.png',test) center = round((right[0]+left[0]+3)/2) center = int(center) self.moveMouse(center,left[1]+90) self.sleep(0.3,0.5) autoit.control_send(self.title, '', '{F3}', 0) res = self.findHP(); if res > 0: autoit.control_send(self.title, '', '{F1}', 0) self.sleep(0.1,0.4) return if (self.findFromTargeted(left, right)): autoit.mouse_click('left', center, left[1]+90) self.sleep(0.1,0.3) autoit.mouse_click('left', center, left[1]+90) return True self.mouseRotate()
def fooExample(): import autoit # autoit.run("notepad.exe") # autoit.win_wait_active("[CLASS:Notepad]", 3) # autoit.control_send("[CLASS:Notepad]", "Edit1", "hello world{!}") # autoit.win_close("[CLASS:Notepad]") # autoit.control_click("[Class:#32770]", "Button2") # new: change Jabber to active autoit.mouse_click("right",1596,1080,1) autoit.win_wait_active("Cisco Jabber", 3) autoit.mouse_click("left", 1600, 920, 1)
def clickTemplate(self, templateName, dir, mouse_btn): find = self.findTemplate(templateName, dir) if (find): min_val, max_val, min_loc, (x1,y1) = find print (find) # roi2 = roi[y1:y1+th, x1:x1+tw] # print 352+x1 # print 875+y1 # cv2.imshow("2", roi) # cv2.waitKey(0) # bla() autoit.mouse_click(mouse_btn, self.leftCornerx+x1+3, self.leftCornery+y1+3) return True print 'not_click '+ templateName return False
def ns_refresh_system(): # ai.win_activate("[CLASS:Afx:00D80000:8:00010003:00000000:014702D7]") #ai.win_activate('[CLASSNAMENN:SysTreeView322]') try: ai.win_activate('[title:NetLinx Studio]') except ai.AutoItError: print('AutoItError happened, returned') return #ai.control_focus('[title:NetLinx Studio]','SysTreeView322') ai.opt("MouseCoordMode", 2) ai.mouse_click("right", 20, 200) time.sleep(0.5) ai.mouse_click("left", 40, 130) print('refresh sucess')
def main(): autoit.win_wait(title, 5) counter = 0 cycle = True sleep(3, 3) while cycle: autoit.mouse_click('right', 768, 804) sleep(0.1, 0.2) counter += 1 if counter > 861: cycle = False print counter if counter % 100 == 0: sleep(3, 5) pass
def addfile(self, windowname, filename): '''pyautoit实现上传附件''' # autoit.mouse_click(x=630, y=255) sleep(1.5) if autoit.win_exists(windowname): autoit.win_active(windowname) autoit.mouse_click(x=1580, y=46) APPLICATION_PATH = self.Base_dir() + r'/data/uploadfile' autoit.send(APPLICATION_PATH) autoit.send('{ENTER}') autoit.mouse_click(x=780, y=970) autoit.send(filename) autoit.send('!o') sleep(1) else: raise Exception('没有打开文件窗口')
def main(): autoit.win_wait(title, 5) counter = 0 cycle = True sleep(3,3) while cycle: autoit.mouse_click('right', 768, 804) sleep(0.1,0.2) counter += 1 if counter > 861: cycle = False print counter if counter % 100 == 0: sleep(3,5) pass
def main(): autoit.win_wait(title, 5) counter = 0 splcnt = 0 poitonUse = 0 cycle = True while cycle: hpstatus = checkOwnHp() print 'hp ' + str(hpstatus) if hpstatus == -1: print 'CPDamage' cv2.imwrite('CPDamage' + str(int(time.time())) + '.png', getScreen(leftCornerx, leftCornery, x2, fullY2)) cycle = False # autoit.win_kill(title) if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png', getScreen(leftCornerx, leftCornery, x2, fullY2)) cycle = False if hpstatus == 1: if poitonUse == 0: autoit.control_send(title, '', '{F10}', 0) poitonUse += 1 if poitonUse > 5: poitonUse = 0 else: poitonUse = 0 img = getScreen(leftCornerx, leftCornery, x2, y2) res = findHP(img) print 'tgs ' + str(res) if res > 0: autoit.control_send(title, '', '{F1}', 0) counter = 0 sleep(2, 4) else: if counter < 1: autoit.control_send(title, '', '{F3}', 0) counter += 1 else: autoit.mouse_click('left', px, py1) sleep(0.5, 1.5) autoit.control_send(title, '', '{F4}', 0) counter = 0 pass
def cancelSkills(): # open bottom menu bottomMenuExit() openBMenu(Icons.BMenu_Tap.name) # sword master lv up autoit.mouse_click('left', hero_btn_x, swordmaster_btn_y, 1, 5) distance_btn_y = 88 y = tapmenu_btn_init_y - distance_btn_y for i in range(5): y += distance_btn_y autoit.mouse_click('left', hero_btn_x, y, 1, 5) time.sleep(1) bottomMenuExit()
def lvupActiveSkill(mode='SC'): print(f'Tap menu lv up') # open bottom menu bottomMenuExit() openBMenu(Icons.BMenu_Tap.name) # scroll up menuScrollUp() # for lv up all skills # sword master lv up autoit.mouse_click('left', hero_btn_x, swordmaster_btn_y, 1, 5) time.sleep(0.5) # active skills # 451, 541, 626, 717, 802, 896 , x = 370 c= 0xe00000 distance_btn_y = 88 skill_list = tap_active_skill_lists[mode] y = tapmenu_btn_init_y - distance_btn_y for i, sk in enumerate(skill_list): y += distance_btn_y # check diabled skill if sk[1] == 0: continue # check on skills color ef6e14 if not IsColorAtCoord(hero_btn_x, y, CR_ActiveSkill_btn) \ and not IsColorAtCoord(hero_btn_x, y, CR_ActiveSkill_btn2): continue # color = autoit.pixel_get_color(hero_btn_x, y) # c = color & 0xff # print(f'tapmenu btn color', {y}, {hex(c)}) # if 0xc6 <= c <= 0xcf: # continue autoit.mouse_click('left', hero_btn_x, y, 1, 10) # check lv number if sk[1] == 1: continue #else lv up max # check if possible lv up time.sleep(0.3) if IsColorAtCoord(tapmenu_skill_lvbtn_x, y, CR_AtiveSkill_lvup_btn): autoit.mouse_click('left', tapmenu_skill_lvbtn_x, y, 1, 5) time.sleep(0.1) # check Mega boost if not IsColorAtCoord(hero_btn_x, tapmenu_megaboost_btn_y, c_megaboost): autoit.mouse_click('left', hero_btn_x, tapmenu_megaboost_btn_y, 1, 10) bottomMenuExit()
def main(): autoit.win_wait(title, 5) counter = 0 splcnt = 0 poitonUse = 0 cycle = True while cycle: hpstatus = checkOwnHp() print 'hp ' + str(hpstatus) if hpstatus == -1: print 'CPDamage' cv2.imwrite('CPDamage' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False # autoit.win_kill(title) if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False if hpstatus == 1: if poitonUse == 0: autoit.control_send(title, '', '{F10}', 0) poitonUse += 1 if poitonUse > 5: poitonUse = 0 else: poitonUse = 0 img = getScreen(leftCornerx,leftCornery,x2,y2) res = findHP(img); print 'tgs ' + str(res) if res > 0: autoit.control_send(title, '', '{F1}', 0) counter = 0 sleep(2,4) else: if counter < 1: autoit.control_send(title, '', '{F3}', 0) counter += 1 else: autoit.mouse_click('left', px, py1) sleep(0.5,1.5) autoit.control_send(title, '', '{F4}', 0) counter = 0 pass
def click_point_from_city(city): if city in ['Cranbrook', 'Elko', 'Grasmere', 'Jaffray']: x = 2206 elif city in ['Kimberley', 'Moyie', 'Wardner', 'Wasa']: x = 2608 elif city in ['Wycliffe', 'Yahk']: x = 3011 else: x = 3414 if city in ['Cranbrook', 'Kimberley', 'Wycliffe']: y = 819 - 48 elif city in ['Elko', 'Moyie', 'Yahk']: y = 843 - 48 elif city in ['Grasmere', 'Wardner', None]: y = 865 - 48 else: y = 893 - 48 autoit.mouse_click("left", x, y)
def findTarget(): img = getScreen(leftCornerx, leftCornery, x2, y2) cnts = getTargetCntrs(img) approxes = [] hulls = [] for cnt in cnts: approxes.append( cv2.approxPolyDP(cnt, 0.01 * cv2.arcLength(cnt, True), True)) hulls.append(cv2.convexHull(cnt)) left = list(cnt[cnt[:, :, 0].argmin()][0]) right = list(cnt[cnt[:, :, 0].argmax()][0]) print 'left x' + str(left[0]) + 'y ' + str(left[1]) print 'right x' + str(right[0]) + 'y ' + str(right[1]) if right[0] - left[0] < 20: print 'Small diff ' + str(right[0] - left[0]) continue center = round((right[0] + left[0]) / 2) center = int(center) moveMouse(center, left[1] + 90) sleep(0.2, 0.4) res = findHP(img) if res > 0: autoit.control_send(title, '', '{F1}', 0) sleep(0.1, 0.4) return if (findFromTargeted(left, right)): autoit.mouse_click('left', center, left[1] + 90) sleep(0.1, 0.3) autoit.mouse_click('left', center, left[1] + 90) return True # moveMouse(center,left[1]+70) # res = findHP(img); # if res > 0: # autoit.control_send(title, '', '{F2}', 0) # return # if (findFromTargeted(left, right)): # autoit.mouse_click('left', center+10, left[1]+70) # return True mouseRotate()
def clickBuff(self, clickname): template = cv2.imread('buffs/' + clickname, 0) th, tw = template.shape[:2] roi = self.getScreen(352, 875, 865, 1063) # cv2.imshow("roi", roi) # cv2.waitKey(0) # bla() roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY) res = cv2.matchTemplate(roi, template, cv2.TM_CCORR_NORMED) if (res.any()): min_val, max_val, min_loc, (x1,y1) = cv2.minMaxLoc(res) # roi2 = roi[y1:y1+th, x1:x1+tw] # print 352+x1 # print 875+y1 # cv2.imshow("2", roi) # cv2.waitKey(0) # bla() if (max_val > 0.98): autoit.mouse_click('left', 352+x1+int(round(tw/2)), 875+y1+int(round(th/2))) return True print 'not_click '+ clickname return False
def findTarget(): img = getScreen(leftCornerx,leftCornery,x2,y2) cnts = getTargetCntrs(img) approxes = [] hulls = [] for cnt in cnts: approxes.append(cv2.approxPolyDP(cnt,0.01*cv2.arcLength(cnt,True),True)) hulls.append(cv2.convexHull(cnt)) left = list(cnt[cnt[:,:,0].argmin()][0]) right = list(cnt[cnt[:,:,0].argmax()][0]) print 'left x' + str(left[0])+ 'y '+ str(left[1]) print 'right x' + str(right[0])+ 'y '+ str(right[1]) if right[0] - left[0] < 20: print 'Small diff ' + str(right[0] - left[0]) continue center = round((right[0]+left[0])/2) center = int(center) moveMouse(center,left[1]+90) sleep(0.2,0.4) res = findHP(img); if res > 0: autoit.control_send(title, '', '{F1}', 0) sleep(0.1,0.4) return if (findFromTargeted(left, right)): autoit.mouse_click('left', center, left[1]+90) sleep(0.1,0.3) autoit.mouse_click('left', center, left[1]+90) return True # moveMouse(center,left[1]+70) # res = findHP(img); # if res > 0: # autoit.control_send(title, '', '{F2}', 0) # return # if (findFromTargeted(left, right)): # autoit.mouse_click('left', center+10, left[1]+70) # return True mouseRotate()
def program_start(): global main_queue main_queue = queue.Queue() while(True): vision(main_queue) if main_queue.qsize() > 0: print('In queue have' + str(main_queue.qsize())) element = main_queue.get() print(element['rectangles']) if element['type'] == 'monster': print('monster found on ' + str(element['rectangles'][0][0] + int(element['rectangles'][0][2] / 2)) + ',' + str(element['rectangles'][0][1] + int(element['rectangles'][0][3] / 2))) autoit.mouse_click("left", element['rectangles'][0][0] + int(element['rectangles'][0][2] / 2), element['rectangles'][0][1] + int(element['rectangles'][0][3] / 2), 1) time.sleep(4) else: time.sleep(1) if keyboard.is_pressed('Esc'): print("\nyou pressed Esc, so exiting...") break
def posionDagger(): # 177, 427 # dagger color 4d7f24, 4a 84 29 for d in daggers: # is there dagger? if isThereDagger(d[0], d[1]): # if True: autoit.mouse_click('left', d[0], d[1]+20, 3, 5) # tap during 2s on the fairy position tap(487, 299) # autoit.mouse_click('left', 286, 610, 1) for i in range(30): tapCursor() # dagger & firay concurrently # _tap('fairycollect') tapFairyCollect() time.sleep(0.6)
def main(): user_dir = get_users_main_directory() check_lp_power_data_folder_exists(user_dir) check_database_file_exists(user_dir) trial = {} trial = prompt_setup(trial, user_dir) # stopgap for pre-class variables walk_speed = trial["Speed [MPH]"] walk_style = trial["Walk Style [Normal/LP]"] pack_number = trial["Pack Number [XXX]"] # MAKE FOLDERS FOR TRIAL BASED ON PREVIOUSLY-ENTERED INPUTS make_pack_folder(pack_number, walk_speed, walk_style, user_dir) print('.....') print("..........Launching.....") # SET UP BASIC AUTO-IT SETTINGS TO USE WINDOW-RELATIVE COORDINATES autoit.auto_it_set_option('MouseCoordMode', 0) autoit.auto_it_set_option('SendKeyDelay', 10) # OPEN PICOSCOPE USING OUR DEFAULT WINDOW LAYOUT WITH TWO PANELS AND POWER UP TOP default_pico = os.path.join(user_dir, "electrical_power.psdata") click_on_file(default_pico) # PREPARE TO RUN THE RECORD DATA MACRO autoit.win_wait('PicoScope 6 - [electrical_power.psdata]') autoit.win_activate('PicoScope 6 - [electrical_power.psdata]') time.sleep(0.5) autoit.send('{ALT}{TAB}{TAB}{TAB}{TAB}{ENTER}{END}{UP}{ENTER}') autoit.win_wait('Macro Recorder') autoit.control_click('Macro Recorder', "[Name:_buttonImport]") time.sleep(1) macro_text = os.path.abspath(os.path.join(user_dir, "record_20sec.psmacro")) autoit.clip_put(macro_text) autoit.win_wait("Open") autoit.send('^V', 0) autoit.send('{ENTER}') msgbox("Ready to go?") # RUN THE MACRO autoit.win_activate('Macro Recorder') autoit.win_wait('Macro Recorder') autoit.control_click('Macro Recorder', "[Name:_buttonExecute]") time.sleep(22) autoit.win_activate('Macro Recorder') autoit.send('{ESCAPE}') # BEGIN SAVING THE DATA i = datetime.now() save_text = os.path.abspath(os.path.join(user_dir, 'LP Power Data', "{}".format("LP-{0}".format(pack_number)), "{0}MPH-{1} Walk".format(walk_speed, walk_style), "{0}MPH-{1} Walk_".format(walk_speed, walk_style) + i.strftime('%Y-%m-%d %Hh%Mm%Ss')+ ".psdata")) autoit.clip_put(save_text) # SAVE ALL CAPTURED WAVEFORMS IN PICO FORMAT autoit.win_activate('PicoScope 6') autoit.win_wait("PicoScope 6") autoit.send('{ALT}{f}{a}') time.sleep(.5) autoit.win_wait("Save As") autoit.control_send('Save As', "[Class:Edit;INSTANCE:1]", '^V', 0) autoit.send('{ENTER}') # BEGIN SAVE SEQUENCE FOR CSV FORMAT autoit.win_activate('PicoScope 6') autoit.win_wait("PicoScope 6") autoit.mouse_click("primary", 433, 67, 2, 1) # MUST CLICK ON SECTION OF WINDOW CONTAINING POWER TRACE OR ALL AVERAGES CALCULATED WILL BE MESSED UP autoit.win_activate('PicoScope 6') autoit.win_wait("PicoScope 6") autoit.mouse_click("primary", 230, 260, 1, 0) # autoit.control_click('PicoScope 6', "[CLASS:WindowsForms10.Window.8.app.0.1114f81_r13_ad1; INSTANCE:55]") autoit.send('{ALT}{f}{a}') time.sleep(.5) autoit.win_wait("Save As") autoit.control_send('Save As', "[Class:Edit;INSTANCE:1]", '^V', 0) # SAVE ALL CAPTURED 5SEC INTERVALS autoit.control_click('Save As', "[CLASS:ComboBox;INSTANCE:3]") autoit.send("{HOME}{DOWN}{DOWN}{ENTER}") # autoit.control_click("Save As", "[NAME:_currentBufferRadio]") time.sleep(0.5) autoit.send('{ENTER}') time.sleep(4.5) autoit.process_close('PicoScope.exe') # BOTH SAVE OPERATIONS NOW COMPLETE. THERE IS A CSV FOR EACH 5SEC INTERVAL IN A NEW SUBDIRECTORY OF THIS TRIAL. print("") print("Sit tight, I'm still doing some thinking....") # UPDATE ALL CSV FILES TO BE XLSX AND CALCULATE THEIR 5SEC AVERAGES run_avgs = recursively_repair_all_csv_files(save_text, user_dir, walk_speed) # ADD ALL INFORMATION COLLECTED TO THE EXPERIMENTS SPREADSHEET patch_experiments_database(trial, run_avgs, user_dir) print("") # WRITE THE METADATA SETTINGS TO A FILE FOR FUTURE RECORD with open('{}'.format(save_text.replace(".psdata", ".LPmeta")), 'w') as outfile: json.dump(trial, outfile, indent=4, separators=(',', ': ')) print("") print("LP Metadata file successfully saved for the future with all info the state of the pack as you have just tested it.") print("") # print_average_power(dest_filename) print(".................................. Testing Complete.")
def randClick(self, a, b, button): autoit.mouse_click(button, int(random.uniform(a+2, a-2)), int(random.uniform(b+2, b-2)))
def restoreMenyHp(): template = cv2.imread('template_button.png', 0) cycle = True while cycle: autoit.mouse_click('left', 1365, 983) sleep(0.3,0.7) autoit.mouse_click('left', 1250, 704) sleep(0.6,0.7) button = getScreen(540, 170, 675, 220) button = cv2.cvtColor(button, cv2.COLOR_BGR2GRAY) res = cv2.matchTemplate(button, template, cv2.TM_CCORR_NORMED) if (res.any()): min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) print 'menuval %.2f'%max_val if (max_val > 0.9): autoit.mouse_click('left', 606, 189) sleep(0.3,0.7) autoit.mouse_click('left', 729, 322) sleep(0.4,0.9) autoit.mouse_click('left', 1043, 92) sleep(0.4,0.9) autoit.mouse_click('left', 1378, 670) cycle = False else: autoit.mouse_click('left', 1043, 92) sleep(0.4,0.9) autoit.mouse_click('left', 1378, 670)
def main(): autoit.win_wait(title, 5) counter = 0 poitonUse = 0 cycle = True fightCounter = 0 rage = 0 while cycle: cpstatus = checkOwnCp() hpstatus = checkOwnHp() print 'hp ' + str(hpstatus) if cpstatus == -1: print 'CPDamage' cv2.imwrite('CPDamage' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False # autoit.win_kill(title) if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False if hpstatus == 1: if poitonUse == 0: autoit.control_send(title, '', '{F10}', 0) poitonUse += 1 if poitonUse > 5: poitonUse = 0 else: poitonUse = 0 if (not matchBuff('template_rage.png',360,80)): if (rage == 0): autoit.mouse_click('left', 1485, 885) sleep(0.1,0.3) rage += 1 autoit.control_send(title, '', '{F1}', 0) if (rage > 5): rage = 0 else: rage = 0 img = getScreen(leftCornerx,leftCornery,x2,y2) res = findHP(img); print 'tgs ' + str(res) if res > 0: autoit.control_send(title, '', '{F1}', 0) counter = 0 if res == 1: sleep(0.3,0.6) if res > 1: sleep(2,4) else: if counter < 2: autoit.control_send(title, '', '{F3}', 0) sleep(0.1,0.2) autoit.control_send(title, '', '{F1}', 0) if counter >= 2: # autoit.control_send(title, '', '{F11}', 0) # findTarget() autoit.control_send(title, '', '{F11}', 0) sleep(0.1,0.2) autoit.control_send(title, '', '{F3}', 0) # sleep(0.1,0.2) # autoit.control_send(title, '', '{F1}', 0) counter = 0 counter += 1 print 'cnt ' + str(counter) pass