def test_moveRel(self): # start at the center desired = self.center pyautogui.moveTo(*desired) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # move down and right desired += P(42, 42) pyautogui.moveRel(42, 42) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # move up and left desired -= P(42, 42) pyautogui.moveRel(-42, -42) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # move right desired += P(42, 0) pyautogui.moveRel(42, None) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # move down desired += P(0, 42) pyautogui.moveRel(None, 42) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # move left desired += P(-42, 0) pyautogui.moveRel(-42, None) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # move up desired += P(0, -42) pyautogui.moveRel(None, -42) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # Passing a list instead of separate x and y. desired += P(42, 42) pyautogui.moveRel([42, 42]) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # Passing a tuple instead of separate x and y. desired -= P(42, 42) pyautogui.moveRel((-42, -42)) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # Passing a sequence-like object instead of separate x and y. desired += P(42, 42) pyautogui.moveRel(P(42, 42)) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired)
def main(): while True: position = pyautogui.position() time.sleep(60) if position == pyautogui.position(): pyautogui.moveRel(0,-1) pyautogui.moveRel(0,1)
def Start(pos): pyautogui.FAILSAFE = False global root, running im=pyautogui.screenshot() pos['text']=str(pyautogui.position()) rgb['text']=str(im.getpixel(pyautogui.position())) root.update_idletasks() root.after(10, lambda:Start(pos))
def func(): self.screenshot_button.config(state='disabled') for second in reversed(range(4)): self.screenshot_label.config( text='Deselect the game window %s' % second) if second != 0: time.sleep(1) region = [] for second in reversed(range(4)): self.screenshot_label.config( text='Place the mouse at the top left\nof the game\'s title bar %s' % second) if second != 0: time.sleep(1) constant_top_left = pyautogui.position() region.extend(constant_top_left) for second in reversed(range(4)): self.screenshot_label.config( text='Place the mouse at the bottom right\nof the game\'s title bar %s' % second) if second != 0: time.sleep(1) constant_bottom_right = pyautogui.position() region.extend( (constant_bottom_right[0] - constant_top_left[0], constant_bottom_right[1] - constant_top_left[1]) ) self.deselected_screenshot = pyautogui.screenshot(region=region) pyautogui.click() self.selected_screenshot = pyautogui.screenshot(region=region) for second in reversed(range(4)): self.screenshot_label.config( text='Place mouse at the top left\nof the entire game window %s' % second) if second != 0: time.sleep(1) top_left = pyautogui.position() for second in reversed(range(4)): self.screenshot_label.config( text='Place mouse at the bottom right\nof the entire game window %s' % second) if second != 0: time.sleep(1) bottom_right = pyautogui.position() self.screen_size = [ constant_top_left[0] - top_left[0], constant_top_left[1] - top_left[1], bottom_right[0] - constant_bottom_right[0], bottom_right[1] - constant_bottom_right[1] ] self.screenshot_taken = True self.screenshot_label.config(text='Screenshot Taken') self.screenshot_button.config( state='normal', text='Retake Screenshot')
def showLocation(): lastLoc = (0,0) newLoc = (1,0) while lastLoc != newLoc: x, y = pyautogui.position() time.sleep(0.25) locX.delete(0,END) locY.delete(0,END) locX.insert(0,x) locY.insert(0,y) lastLoc = newLoc newLoc = pyautogui.position()
def v_scroll_on_android(scroll_value=20, locate_first_on_center = True, scrollDown = True): # Locate the mouse on screen center if(locate_first_on_center is True): locate_on_center() # Simulate drag and drop # pyautogui.mouseDown(); x, y = pyautogui.position()[0], pyautogui.position()[1] if(scrollDown is True): y = y - scroll_value; else: y = y + scroll_value; pyautogui.dragTo(x, y)
def onClick(self, mouse_button): if mouse_button == 4: #scroll up prev = pyautogui.position() pyautogui.moveTo(0, pyautogui.size()[1], pause=False) pyautogui.scroll(1) pyautogui.moveTo(*prev, pause=False) elif mouse_button == 5: #scroll dn prev = pyautogui.position() pyautogui.moveTo(0, pyautogui.size()[1], pause=False) pyautogui.scroll(-1) pyautogui.moveTo(*prev, pause=False) else: #do nothing pass
def test_position(self): mousex, mousey = pyautogui.position() self.assertTrue(isinstance(mousex, int), 'Type of mousex is %s' % (type(mousex))) self.assertTrue(isinstance(mousey, int), 'Type of mousey is %s' % (type(mousey))) # Test passing x and y arguments to position(). pyautogui.moveTo(mousex + 1, mousey + 1) x, y = pyautogui.position(mousex, None) self.assertEqual(x, mousex) self.assertNotEqual(y, mousey) x, y = pyautogui.position(None, mousey) self.assertNotEqual(x, mousex) self.assertEqual(y, mousey)
def auto_mouse(): auto.moveTo(450,450) pos = auto.position() auto.moveRel(-200,-200) pos2 = auto.position() for i in range(100 ): try: auto.moveTo(pos, duration = 1, tween = auto.easeInCubic) auto.click() auto.moveTo(pos, duration = 1) auto.click() auto.moveTo(pos2,duration = 1, tween = auto.easeInQuad) except: sys.exit()
def test_moveTo(self): # moving the mouse desired = self.center pyautogui.moveTo(*desired) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # no coordinate specified (should be a NO-OP) pyautogui.moveTo(None, None) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # moving the mouse to a new location desired += P(42, 42) pyautogui.moveTo(*desired) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # moving the mouse over time (1/5 second) desired -= P(42, 42) pyautogui.moveTo(desired.x, desired.y, duration=0.2) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # moving the mouse with only x specified desired -= P(42, 0) pyautogui.moveTo(desired.x, None) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # ...and only y specified desired -= P(0, 42) pyautogui.moveTo(None, desired.y) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # Passing a list instead of separate x and y. desired += P(42, 42) pyautogui.moveTo(list(desired)) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # Passing a tuple instead of separate x and y. desired += P(42, 42) pyautogui.moveTo(tuple(desired)) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # Passing a sequence-like object instead of separate x and y. desired -= P(42, 42) pyautogui.moveTo(desired) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired)
def test(): i = 0 while i < 5: i = i + 1 print pyautogui.position() #window = pyautogui.locateCenterOnScreen('wood.png') windows = pyautogui.locateAllOnScreen('key.png') #if window is None: # sys.exit('Could not find game on screen. Is the game visible?') for window in windows: l = window[0] t = window[1] w = window[2] h = window[3] time.sleep(0.1) pyautogui.moveTo(l+w/2, t+h/2)
def initialize(): if not os.getenv('GOOGLE_API_KEY'): print('*' * 80) print('You must set GOOGLE_API_KEY to OS environments.') print('Please check https://developers.google.com/maps/documentation/javascript/get-api-key') print("export GOOGLE_API_KEY='blahblah' to ~/.bash_profile") print('*' * 80) raise NameError('GOOGLE_API_KEY') print("Cursor on GPS button of xcode.") input("press enter to continue") gps_button_pos = pyautogui.position() print("Cursor on GPX file of xcode. (pikapika.gpx)") input("press enter to continue") gpx_file_pos = pyautogui.position() return gps_button_pos, gpx_file_pos
def __init__(self,mag=100, browser='Firefox'): top_bar = {'Firefox':100,'Chrome':115} self.__x, self.__y = position() self.__top_bar = top_bar[browser] self.__y -= top_bar[browser] self.__center = False self.__mag = mag
def clickAndReturnMouse(img): orig_x,orig_y = pyautogui.position() pyautogui.moveTo(img['points'][0]['center'][0],img['points'][0]['center'][1]) pyautogui.click() logging.info('CLICK') pyautogui.moveTo(orig_x, orig_y) return
def keysGui(cmdKeys,changeVar): def loadKey(lb,changeVar): keyToLoad = int(lb.curselection()[0]) keyStr = cmdKeys[keyToLoad] changeVar.delete(0,'end') changeVar.insert(0,keyStr) rootC.destroy() rootC = Tk() scrollbar2 = Scrollbar(rootC) scrollbar2.pack(side=RIGHT,fill=BOTH) listbox2 = Listbox(rootC, yscrollcommand=scrollbar2.set,width=40) scrollbar2.config(command=listbox2.yview) for keyK in cmdKeys: listbox2.insert(END,str(keyK)) def clickEvent(event): try: loadKey(listbox2,changeVar) except IndexError: pass currentMousePos = pyautogui.position() listbox2.pack(fill=BOTH,expand=1,side=LEFT) rootC.geometry('{}x{}+{}+{}'.format(320, 430,(currentMousePos[0]-155),currentMousePos[1]-185)) rootC.bind("<Button-1>", clickEvent) rootC.wm_attributes("-topmost",int(True)) rootC.wm_title("List Of Keys") rootC.mainloop()
def clickAndReturnMouse_point(point): orig_x,orig_y = pyautogui.position() pyautogui.moveTo(point['center'][0],point['center'][1]) pyautogui.click() logging.info('CLICK') pyautogui.moveTo(orig_x, orig_y) return
def clickAndReturnMouseCoords(coords): orig_x,orig_y = pyautogui.position() pyautogui.moveTo(coords[0],coords[1]) pyautogui.click() logging.info('CLICK') pyautogui.moveTo(orig_x, orig_y) return
def main(): global base_lat, base_lon print("(1/3)GPS button에 커서를 올려주세요.") input("완료되었으면 엔터를 눌러주세요.") xcode_gps_button_loc = pyautogui.position() print("\n(2/3)GPX file에 커서를 올려주세요.") input("완료되었으면 엔터를 눌러주세요.") xcode_gpx_file_loc = pyautogui.position() print("\n(3/3)터미널에 커서를 올려주세요.") input("완료되었으면 엔터를 눌러주세요.") terminal_loc = pyautogui.position() success, base_lat, base_lon = load_save() if success: print("\n저장파일에서 좌표값을 자동으로 불러왔습니다.") else: print("\n저장파일에서 좌표값 불러오기를 실패했습니다.") print("\n끝! wasd로 움직이고 cmd + c로 종료하세요.\n좌표가 바뀔 때마다 자동으로 저장됩니다.") lat = 0 lon = 0 # 인터럽트가 없는 한 아래를 무한반복한다. while True: k = input_manager() if k == 'w': lat += 1 elif k == 'd': lon += 1 elif k == 's': lat -= 1 elif k == 'a': lon -= 1 # gpx 파일 생성 gen_gpx(lat, lon) # gps 버튼 클릭 pyautogui.moveTo(xcode_gps_button_loc) pyautogui.click() # gpx 클릭 pyautogui.moveTo(xcode_gpx_file_loc) pyautogui.click() # 터미널 클릭 pyautogui.moveTo(terminal_loc) pyautogui.click() return
def real_change(lat_lng_string): if js_develop_mode: return last_pos = pyautogui.position() lat_lng = dict(re.findall(r'([latng]{3})\=([\d\.\-]+)', lat_lng_string)) rewrite_gpx(lat_lng) for pos in gps_button_pos, gpx_file_pos, last_pos: pyautogui.click(*pos)
def grava(): pos = input("Quantas posiçoes deseja salvar?") sec = input("Delay") for i in range(pos): print("Gravando %dª posiçao" % (i)) posicoes.append(pyautogui.position()) time.sleep(sec)
def click(self): currentMouseX, currentMouseY = gui.position() left, top, right, bottom = self.box gui.click(((left + right)) // 2, (top + bottom) // 2) gui.moveTo(currentMouseX, currentMouseY)
def basic_api(): cur_x, cur_y = pag.position() print(cur_x, cur_y) x, y = pag.size() print(x, y) '''
def run(): pergunta_pos1 = input("Aperte enter para salvar a posição: ") pos1 = pyautogui.position() print("posição 1: ", pos1) Pergunta_pos2 = input("Aperte enter para salvar a posição: ") pos2 = pyautogui.position() print("posição 2:", pos2) print("Start AutoFeed") while True: pyautogui.moveTo(pos1, duration=1) pyautogui.click(pos1) print("Click 1") time.sleep(2) pyautogui.moveTo(pos2, duration=1) pyautogui.click(pos2) print("Click 2") print("Alimentar novamente em 10min ") time.sleep(600)#10min
def scroll(self, amount): if amount < 120: amount *= 120 currentMouseX, currentMouseY = gui.position() win32api.mouse_event(MOUSEEVENTF_WHEEL, currentMouseX, currentMouseY, amount, 0) # there is visual lag, prevent further processing until the lag completes time.sleep(.3)
def do_shake(): currentX, currentY = pyautogui.position() for i in range(SHAKES): if i % 2 == 0: pyautogui.moveTo(currentX + MOUSE_MOVE, currentY + MOUSE_MOVE) else: pyautogui.moveTo(currentX - MOUSE_MOVE, currentY - MOUSE_MOVE) sleep(SLEEP)
def checkHover(self,event=None): self.new = timeit.default_timer() if int(self.new-self.old)>2: self.newx,self.newy=gui.position() gui.click(self.oldx,self.oldy) gui.moveTo(self.newx,self.newy) #self.hoverTime() #print(self.old," and ",self.new) else: pass
def keyPress(event): if event.char == " ": x, y = pyautogui.position() locX.delete(0,END) locY.delete(0,END) locX.insert(0,x) locY.insert(0,y) submitEntry(action.get()) elif event.char == "\r": executeAll(allRecordings, freq.get(),delayBetween,echoOn,loopDelay.get(),beep.get())
def handle_command(command): lst = command.split(" ") if lst[0] == 'move': x = int(lst[1]) y = int(lst[2]) (mousex, mousey) = pyautogui.position() pyautogui.moveTo(mousex + x, mousey + y) else: if lst[0] == 'click': pyautogui.doubleClick()
def run(self): mlen = 0; while not self.isStop: self.x, self.y = pyautogui.position(); self.color = pyautogui.pixel(self.x, self.y); r, g, b = self.color; mess = 'Current Mouse: (%d, %d) color:(%d, %d, %d)'%(self.x, self.y,r, g, b); print('\b'*mlen, end=''); print(mess, end='', flush = True); mlen = len(mess);
def test_position(self): mousex, mousey = pyautogui.position() if runningOnPython2 and sys.platform != 'darwin': # Python 2 on OS X returns int. self.assertTrue(isinstance(mousex, long), 'Type of mousex is %s' % (type(mousex))) self.assertTrue(isinstance(mousey, long), 'Type of mousey is %s' % (type(mousey))) else: self.assertTrue(isinstance(mousex, int), 'Type of mousex is %s' % (type(mousex))) self.assertTrue(isinstance(mousey, int), 'Type of mousey is %s' % (type(mousey))) # Test passing x and y arguments to position(). pyautogui.moveTo(mousex + 1, mousey + 1) x, y = pyautogui.position(mousex, None) self.assertEqual(x, mousex) self.assertNotEqual(y, mousey) x, y = pyautogui.position(None, mousey) self.assertNotEqual(x, mousex) self.assertEqual(y, mousey)
def troubleshoot(): while True: print(pyautogui.position())
# add your Yandex mail, password and full link to your VK music page YANDEX_MAIL = "*@yandex.com" PASSWORD = "******" VK_MUSIC_LINK = "https://vk.com/audios240917398" CHROME_ICON = (215, 1055) CHROME_URL = (410, 70) SEARCH = (901, 406) ADD_TRACK = (1462, 525) SWITCH_LANGUAGE_step1 = (1732, 1059) SWITCH_LANGUAGE_RUS = (1817, 834) SWITCH_LANGUAGE_ENG = (1835, 919) # used to determine the location of the cursor screenWidth, screenHeight = pyautogui.size() x, y = pyautogui.position() print((x, y)) def open_browser(): print("Opening Google Chrome browser") pyautogui.click(CHROME_ICON) sleep(1) def add_track(track_fullname): sleep(1) pyautogui.click(SEARCH) sleep(1) pyautogui.hotkey('ctrl', 'a') sleep(1)
#!/usr/bin/env python3 # Controlling keyboard and mouse is called GUI Automation # pip install PyAutoGUI # sudo apt-get install python3-tk python3-dev # (0.0) is the top left corner of the screen # X-axis increases going to right, Y-axis increases going to down import pyautogui width, height = pyautogui.size() # screen resolution print(str(width) + " x " + str(height)) xpos, ypos = pyautogui.position() # position of the mouse cursor print(str(xpos), ", " + str(ypos)) pyautogui.moveTo( 10, 10, duration=1.5) # cursor goes to (10, 10) absolute position in 1.5 seconds pyautogui.moveRel( 200, 10) # moves 200 x-offsets, 10 x-offsets from current cursor position pyautogui.click(954, 0) # single click on 854, 0 absolute position pyautogui.click() # clicks on current cursor position # some more click methods # pyautogui.doubleClick(954, 0) # pyautogui.rightClick(954, 0) # pyautogui.middleClick(954, 0)
# 1. configure socket dest. serverName = '127.0.0.1' serverPort = 12345 clientSocket = socket(AF_INET, SOCK_STREAM) try: clientSocket.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1) clientSocket.connect((serverName, serverPort)) print(clientSocket.getsockopt(SOL_SOCKET, SO_KEEPALIVE)) except ConnectionRefusedError as e: print("Server refused connection. retrying") time.sleep(1) continue # 2. communication routine while (1): [mouseX, mouseY] = pyautogui.position() if mouseX < (screenWidth - 2) and mouseVX > 0: mouseVX -= 1 data = json.dumps({"x": mouseVX, "y": mouseY}) try: clientSocket.send(bytes(data, "utf8")) except ConnectionResetError as e: print("Server connection closed") break pyautogui.moveTo(screenWidth - 2, mouseY) if mouseX > (screenWidth - 2): mouseVX += 1 data = json.dumps({"x": mouseVX, "y": mouseY}) try: clientSocket.send(bytes(data, "utf8")) except ConnectionResetError as e:
import pyautogui as auto auto.FAILSAFE = True print("this code ran") #auto.mouseDown(x=None, y=None, button="left") #auto.mouseUp(x=None,y=None, button="left") """ pyautogui.position() pyautogui.moveTo(100, 200) pyautogui.click() print('Press Ctrl-C to quit.') """ try: while True: x, y = auto.position() positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4) print(positionStr, end='') print('\b' * len(positionStr), end='', flush=True) except KeyboardInterrupt: print('\n') """ def tamadora(): pyautogui.moveTo(100, 200) pyautogui.click() """
print p0[1] px = {} py = {} px[0] = p0[0] py[0] = p0[1] #px = [] #px.append(p0[0]) #py = [] #py.append(p0[1]) tts.say("始まります") t0 = time.clock() motion.moveToward(vx0, vy0, 0.0) x0, y0 = pyautogui.position() x = {} #mouse x y = {} #mouse y x[0] = x0 y[0] = y0 vx = {} #pepper command velocity calculated by mouse position vy = {} #pepper command velocity calculated by mouse position vx[0] = vx0 vy[0] = vy0 vmx = {} #mouse velocity vmy = {} #mouse velocuty vmx[0] = 0 vmy[0] = 0 vecx = {} #mouse velocity
# Fill the circle with white color cv2.circle(screen, (x, y), radius, (255, 255, 255), -1, 8, 0) # Draw the boundary of the circle cv2.circle(screen, (x, y), radius, (0, 0, 255), 2, 8, 0) else: # Draw the center point of the circle cv2.circle(screen, (x, y), 3, (15, 230, 15), -1, 8, 0) # Draw the boundary of the circle cv2.circle(screen, (x, y), radius, (15, 230, 15), 2, 8, 0) # Auto-gaming logic if autoGaming and maxIdx >= 0: currentTime = time.time() if 1000.0 * (currentTime - lastAutoGameTime) > autoGamingMs: max_x, max_y, _ = circles[maxIdx] prevMouse = pyautogui.position() pyautogui.click(x=(crop_x1 + max_x), y=(crop_y1 + max_y)) pyautogui.moveTo(*prevMouse) # Stay focus/active on the OpenCV window for we will miss the # keyboard event if we don't focus on the window pyautogui.click(*prevMouse) lastAutoGameTime = time.time() # Processing time of this frame endTime = time.time() procMs = 1000.0 * (endTime - beginTime) waitMs = max(frameMs - procMs, 1) # 0 means wait indefinitely # Display processing time of each frame cv2.putText(screen, '{:.2f} ms'.format(procMs), (8, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1, cv2.LINE_AA)
text1 = "Для получения координат осталось: " print(" ") print("Забросьте удочку") text2 = "до следующего действия осталось: " delayNew(5, text2) #верхний левый угол LEFTcurrentMouseX = 0 LEFTcurrentMouseY = 27 print(" ") print("Наведите правый нижний угол рамки рыбалки") delayNew(10, text1) RIGHTcurrentMouseX, RIGHTcurrentMouseY = pyautogui.position() print('Отлично, координаты скилы получены. Теперь бот начинает ловить рыбу') print(" ") BluePixel = [(138, 197, 207), (145, 182, 188), (73, 143, 175), (65, 143, 175), (75, 136, 165), (67, 163, 198), (64, 129, 164), (233, 245, 223), (185, 220, 214), (16, 122, 163), (66, 130, 162), (90, 174, 201), (56, 156, 196), (83, 187, 221), (46, 108, 152)] action = 0 LastBlue = 0 i = 0 while i < 1: #cкрин определяет нужно ли закидывать удочку screenFirst = pyautogui.screenshot( 'screenshot.png',
def execute(self): print(sys.argv) game_name_list = [] for k, v in lybconfigure.LYBConstant.LYB_GAMES.items(): game_name_list.append(k) if len(game_name_list) > 1: if len(sys.argv) > 1: game_number = int(sys.argv[1]) else: print('----------------------') for game_name in game_name_list: print(game_name_list.index(game_name) + 1, game_name) print('----------------------') print("Select Game: ", end='') game_number = input() else: game_number = 0 if len(str(game_number)) == 0: game_number = 0 self.filename = lybconfigure.LYBConstant.LYB_GAMES[game_name_list[ int(game_number) - 1]] + '.lyb' print("filename: ", self.filename) if len(sys.argv) > 2: self.window_title = ".*" + str(sys.argv[2]) + ".*" else: self.window_title = ".*" + ".*" # self.window_title = ".*"+'녹스'+".*" # self.window_title = ".*"+'모모 5'+".*" # self.window_title = '.*' + 'NoxPlayer' + '.*' try: with open(self.resource_path(self.filename), 'rb') as resource_file: self.resource_manager = pickle.load(resource_file) except: self.resource_manager = lybresource.LYBResourceManager( lybresource.LYBPixelBoxDic(), lybresource.LYBResourceDic()) # self.resource_manager.debug() window = lybwin.LYBWin('.*cmd\.exe - python.*make_resource_file.py.*') window.find_window_wildcard(self.window_title) if len(window.handle_list) < 1: print('Not found window:', self.window_title) sys.exit() print(window.my_handle) print("'E' : New resource data") print("'G' : Pick 7x7 pixels") print("'A' : Pick 15x15 pixels") print("'S' : Pick 31x31 pixels") print("'D' : Pick 63x63 pixels") print("'F' : Remove resource data") print("'Z' : Search resource data") print("'W' : Confirm") print("'R' : Redraw") print("'T' : Delete all pixel box not in resource") print("'Q' : Save & Quit") window.set_foreground_console(window.handle_list[0]) print(window.get_player(window.handle_list[0]), game_name_list[int(game_number) - 1]) adj_x, adj_y = window.get_player_adjust(window.handle_list[0]) self.anchor_x, self.anchor_y, self.bx, self.by = win32gui.GetWindowRect( window.handle_list[0]) self.anchor_x += adj_x self.anchor_y += adj_y pass_count_for_name = 10 pixel_box = None resource_pixel_box_list = [] resource_name = '' parent_resource_name = '' current_resource = None resource_type = 'etc' is_working = False is_done = False is_ready = False while True: x, y = pyautogui.position() positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4) + \ ' ' + str(pyautogui.pixel(x, y)).rjust(16) + \ ' ' + 'R-X: ' + str(x - self.anchor_x).rjust(4) + ' R-Y: ' + str(y - self.anchor_y).rjust(4) print(positionStr, end='') print('\b' * len(positionStr), end='', flush=True) e = win32api.GetAsyncKeyState(ord('E')) a = win32api.GetAsyncKeyState(ord('A')) g = win32api.GetAsyncKeyState(ord('G')) s = win32api.GetAsyncKeyState(ord('S')) d = win32api.GetAsyncKeyState(ord('D')) w = win32api.GetAsyncKeyState(ord('W')) c = win32api.GetAsyncKeyState(ord('C')) f = win32api.GetAsyncKeyState(ord('F')) z = win32api.GetAsyncKeyState(ord('Z')) r = win32api.GetAsyncKeyState(ord('R')) q = win32api.GetAsyncKeyState(ord('Q')) t = win32api.GetAsyncKeyState(ord('T')) h = win32api.GetAsyncKeyState(ord('H')) if pass_count_for_name > 0: pass_count_for_name -= 1 continue if e != 0: print('\nEnter resource_name: ', end='') resource_name = input() if len(resource_name) < 1: continue try: current_resource = self.resource_manager.resource_dic[ resource_name] except: if 'loc' == resource_name.split('_')[-1]: resource_type = 'location' elif 'scene' == resource_name.split('_')[-1]: resource_type = 'scene' elif 'icon' == resource_name.split('_')[-1]: resource_type = 'icon' elif 'event' == resource_name.split('_')[-1]: resource_type = 'event' else: resource_type = 'etc' print('\n', resource_type, '\n') current_resource = lybresource.LYBResource( resource_name, resource_type) pass_count_for_name = len(resource_name) print('\n') # for each_resource_name, each_resource in self.resource_manager.resource_dic.items(): # print(each_resource_name, ':', each_resource.resource_type) print('Enter parent resource_name: ', end='') parent_resource_name = input() if len(parent_resource_name) > 0: try: parent_rsc = self.resource_manager.resource_dic[ parent_resource_name] if parent_rsc.pixel_box_count > 0: for each_pixel_box_name in parent_rsc: current_resource.append(each_pixel_box_name) except: print('Not found parent resource: ', parent_resource_name) pass_count_for_name += len(parent_resource_name) # for each_name, each_resource in self.resource_manager.pixel_box_dic.items(): # print(each_name) print('Enter pixel_box_name to add: ', end='') pixel_box_name = input() plist = pixel_box_name.split(',') for pname in plist: if len(pname) > 0: if not pname in self.resource_manager.pixel_box_dic: print('Not found pixel_box_name: ', pname) else: current_resource.append(pname) pass_count_for_name += len(pixel_box_name) pixel_box = None resource_pixel_box_list = [] is_working = True is_done = False elif f != 0 and is_working == False: print('\n') # for each_resource_name, each_resource in self.resource_manager.resource_dic.items(): # print(each_resource_name, ':', each_resource.resource_type) # for each_pixel_box_name, each_resource in self.resource_manager.pixel_box_dic.items(): # print(each_pixel_box_name, ':', each_resource.height, each_resource.width) print('\nEnter resource_name to delete: ', end='') resource_name = input() if len(resource_name) < 1: continue if resource_name in self.resource_manager.resource_dic: self.resource_manager.resource_dic.pop(resource_name) print('\ndeleted resource: ', resource_name) else: if resource_name in self.resource_manager.pixel_box_dic: self.resource_manager.pixel_box_dic.pop(resource_name) print('\ndeleted pixel box: ', resource_name) for each_resource_name, each_pixel_box in self.resource_manager.resource_dic.items( ): for each_pb_name in self.resource_manager.resource_dic[ each_resource_name]: if each_pb_name == resource_name: self.resource_manager.resource_dic[ each_resource_name].remove(resource_name) print('\ndeleted pixel box name in', each_resource_name) if len(self.resource_manager. resource_dic[each_resource_name]) == 0: self.resource_manager.resource_dic.pop( each_resource_name) pass_count_for_name = len(resource_name) elif z != 0 and is_working == False: print('\nEnter resource_name to search: ', end='') resource_name = input() if len(resource_name) < 1: continue print('\n') for each_resource_name, each_resource in self.resource_manager.resource_dic.items( ): if resource_name in each_resource_name: print(each_resource_name, ':', each_resource.resource_type) for each_pixel_box_name, each_resource in self.resource_manager.pixel_box_dic.items( ): if resource_name in each_pixel_box_name: print(each_pixel_box_name, ':', each_resource.height, each_resource.width) pass_count_for_name = len(resource_name) elif t != 0 and is_working == False: print('\nEnter to confirm: ', end='') resource_name = input() if len(resource_name) < 1: continue new_pixel_box_dic = lybresource.LYBPixelBoxDic() for each_pixel_box_name, each_pixel_box in self.resource_manager.pixel_box_dic.items( ): if not resource_name in each_pixel_box_name: continue for each_resource_name, each_resource in self.resource_manager.resource_dic.items( ): if each_pixel_box in each_resource: new_pixel_box_dic[ each_pixel_box_name] = each_pixel_box break self.resource_manager.pixel_box_dic = new_pixel_box_dic pass_count_for_name = len(resource_name) elif a != 0 or s != 0 or d != 0 or g != 0 or h != 0 and is_ready == True: if h != 0: size = 4 elif g != 0: size = 8 elif a != 0: size = 16 elif s != 0: size = 32 elif d != 0: size = 64 if self.current_grab_window == None or self.epb == None: print('======================DEBUG1') self.current_grab_window = ImageGrab.grab( bbox=(self.anchor_x, self.anchor_y, self.bx, self.by)) # grabbed_image.save('test_grab.png') self.epb = lybresource.LYBExtractPixelBox( self.anchor_x, self.anchor_y, self.current_grab_window.load()) pixel_box = self.epb.extract_pixel_box(x, y, None, size) if pixel_box != None: print('\nEnter pixel box name: ', end='') pixel_box_name = input() pixel_box.pixel_box_name = pixel_box_name resource_pixel_box_list.append(pixel_box) current_resource.append(pixel_box_name) pass_count_for_name = len(pixel_box_name) is_ready = False elif w != 0: if current_resource != None and len(current_resource) > 0: if len(resource_pixel_box_list) > 0: for each_pixel_box in resource_pixel_box_list: self.resource_manager.pixel_box_dic[ each_pixel_box.pixel_box_name] = each_pixel_box self.resource_manager.resource_dic[ resource_name] = current_resource print('\n\n---------------------------------') print('resource name : ', resource_name) if len(parent_resource_name) > 0: print('parent name : ', parent_resource_name) print('pixel box name : ') for each_pixel_box_name in current_resource: print(' ', each_pixel_box_name) print('\nsuccessfully extracted') print('---------------------------------') self.current_grab_window = None else: print('Not found pixel box information') # is_working = False # is_done = True elif r != 0 and is_working == True: index = 0 print('\n') for each_pixel_box_name in self.resource_manager.resource_dic[ resource_name]: each_pixel_box = self.resource_manager.pixel_box_dic[ each_pixel_box_name] print('\n', index, '-----------------------------') print(each_pixel_box_name, each_pixel_box[0][0][0], each_pixel_box[0][0][1]) self.mouseMove(each_pixel_box_name, each_pixel_box[0][0][0] + self.anchor_x, each_pixel_box[0][0][1] + self.anchor_y) index += 1 print('\n') elif q != 0: with open(self.resource_path(self.filename), 'wb') as resource_file: pickle.dump(self.resource_manager, resource_file) sys.exit() else: if is_working == True and is_ready == False: print('\n\n---------------------------------') print('resource name : ', resource_name) if len(parent_resource_name) > 0: print('parent name : ', parent_resource_name) if len(current_resource) > 0: print('pixel box name : ') for each_pixel_box_name in current_resource: print(' ', each_pixel_box_name) print('\npick location') print('---------------------------------') is_ready = True time.sleep(0.5)
def _on_screen(self, offset_x, offset_y): current_x, current_y = pyautogui.position() return pyautogui.onScreen(current_x + offset_x, current_y + offset_y)
import pyautogui import time print('Write a text to send with emoticion (Only Alphabet)') Text = input() Text2 = list(Text) Count = 0 print('Please Turn On Discord and Ready To Chatting in 10 seconds') print(Text2) time.sleep(10) print('Lets Go') print(pyautogui.position()) # :regional_indicator_ for i1 in Text2: pyautogui.press(':') pyautogui.press('r') pyautogui.press('e') pyautogui.press('g') pyautogui.press('i') pyautogui.press('o') pyautogui.press('n') pyautogui.press('a') pyautogui.press('l') pyautogui.press('_') pyautogui.press('i') pyautogui.press('n') pyautogui.press('d') pyautogui.press('i') pyautogui.press('c') pyautogui.press('a')
import pyautogui print("Mousepos:", pyautogui.position()) print("Screen", pyautogui.size()) box_x = (296, 82) box_y = (1044, 709) print("Within the box: ", pyautogui.onScreen(296, 82)) exit()
break except ValueError: print("Введите число...") print() print("После нажатия \"Enter\" начнёться таймер на 10сек") print("За это время вы должны выделить текстовое поле") print("P.S. Что бы остановить спам пошевелите мышкой") input() time.sleep(10) print("Статус:") print("Прошло времени : Сообщений отправлено") mousePos = pyautogui.position() statusTime = time.time() for x in range(0, amount): if x == round(amount / 5 * 1): print(str(round(time.time() - statusTime, 2)) + ":" + str(x)) if x == round(amount / 5 * 2): print(str(round(time.time() - statusTime, 2)) + ":" + str(x)) if x == round(amount / 5 * 3): print(str(round(time.time() - statusTime, 2)) + ":" + str(x)) if x == round(amount / 5 * 4): print(str(round(time.time() - statusTime, 2)) + ":" + str(x))
import pyautogui import time x = 0 i = input('coloque na posicao 1 e aperte enter') currentUseSpX, currentUseSpY = pyautogui.position() i = input('coloque na posicao 2 e aperte enter') currentUseFoX, currentUseFoY = pyautogui.position() i = input('coloque na posicao 3 e aperte enter') currentUseFo2X, currentUseFo2Y = pyautogui.position() i = input('coloque na posicao 4 e aperte enter') currentUseFo4X, currentUseFo4Y = pyautogui.position() i = input('coloque na posicao 5 e aperte enter') currentUseFo5X, currentUseFo5Y = pyautogui.position() i = input('coloque na posicao 6 e aperte enter') currentUseFo6X, currentUseFo6Y = pyautogui.position() while (x < 10000):
def cursor_postion(): print(pyautogui.position())
import pyautogui as pag from PIL import ImageGrab import keyboard from time import sleep SB = 1 shot = 0 # Value that determines if the target has found start = (670, 446) # Left/Top grid value end = (1248, 847) # Right/Bottom grid value rgb_value = (255, 219, 195) #rgb value of target x, y = pag.position() print((x, y)) sleep(2) ##while SB == 1: ## screen = ImageGrab.grab() # Screen capture ## for i in range (start[0],end[0],10): ## for j in range (start[1],end[1], 10): ## rgb = screen.getpixel((i,j)) # Gathering rgb value from the grid ## if abs(rgb[0] - rgb_value[0])+abs(rgb[1]-rgb_value[1])+abs(rgb[2]-rgb_value[2])<80: ## rgb = screen.getpixel((i+3,j)) ## if abs(rgb[0]-rgb_value[0])+abs(rgb[1]-rgb_value[1])+abs(rgb[2]-rgb_value[2])<80: ## pag.click((i+3,j)) # i+3 because the size of the ball is changing ## shot = 1 ## break ## if shot == 1:# Found target, reset ## shot = 0 ## break ## if keyboard.is_pressed('F3'): #terminate
"index": [6, 8], "middle": [10, 11], "ring": [14, 16], "pinky": [18, 20], } start_point = (50, 40) pyautogui.FAILSAFE = False end_point = (400, 280) h1 = 395 w1 = 395 screen_width = pyautogui.size().width screen_height = pyautogui.size().height # vert_scale= while True: _, img = cap.read() x, y = (pyautogui.position()) cv2.putText(img, message, (20, 30), cv2.FONT_HERSHEY_TRIPLEX, 0.8, (255, 0, 0), 2) # cv2.rectangle(img, start_point, end_point, (255, 0, 0, 1)) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) imgRgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) results = hands.process(imgRgb) if results.multi_hand_landmarks: hands_list = [] for handLndms in (results.multi_hand_landmarks): hand = {} for id, lm in enumerate(handLndms.landmark): h, w, c = img.shape hx, hy = int(lm.x * w), int(lm.y * h) hand[id] = (hx, hy) hands_list.append(hand)
def launch_session(resourcetype, app_name, ddc_url, VDA_name, PIN_passwd): global citrix_receiver_desktops_x, citrix_receiver_desktops_y global vda_pin_center_x, vda_pin_center_y global vda_pin_passwd_x, vda_pin_passwd_y global vda_pin_ok_button_x, vda_pin_ok_button_y global proc_wait_time, opt_wait_time logger.info("") logger.info("[launch_session]:") logger.info( "********************************************************************************************" ) logger.info('citrix_receiver_desktops_x : %d' % (citrix_receiver_desktops_x)) logger.info('citrix_receiver_desktops_y : %d' % (citrix_receiver_desktops_y)) logger.info('vda_pin_center_x : %d' % (vda_pin_center_x)) logger.info('vda_pin_center_y : %d' % (vda_pin_center_y)) logger.info('vda_pin_passwd_x : %d' % (vda_pin_passwd_x)) logger.info('vda_pin_passwd_y : %d' % (vda_pin_passwd_y)) logger.info('vda_pin_ok_button_x : %d' % (vda_pin_ok_button_x)) logger.info('vda_pin_ok_button_y : %d' % (vda_pin_ok_button_y)) logger.info("") logger.info('proc_wait_time : %d' % (proc_wait_time)) logger.info('opt_wait_time : %d' % (opt_wait_time)) logger.info( "********************************************************************************************" ) logger.info("") #os.chdir('D:\\Tools\smartcard') status = 0 logger.info('Resource type is [%s] and app name is [%s].' % (resourcetype, app_name)) logger.info('@@@@@@@@@@@@@@@ start ...') try: #o = subprocess.check_output("start iexplore.exe https://sf.zhusl.com/Citrix/storeWeb/", shell=True) check_cmd = "start iexplore.exe " + ddc_url o = subprocess.check_output(check_cmd, shell=True) logger.info('call iexplore [%s]' % (o)) except Exception as e: #print "Can not start citrix receiver due to %s." % (e) logger.info('Can not start citrix receiver due to [%s]' % (e)) return 2 logger.info("") time.sleep(5) win = None for i in range(0, 61): win = pyautogui.getWindow('Windows Security') logger.info('getWindow result is [%s]' % (win)) if win == None: #print "cannot find Windows Security dialog" logger.info('can not find Windows Security dialog.') time.sleep(1) continue elif win != None: #print "Find Windows Security dialog" logger.info('Find Windows Security dialog.') break if (win == None): #print "Can not find PIN password dialog." logger.info('Can not find PIN password dialog.') return 4 win.set_foreground() time.sleep(1) #pyautogui.typewrite('000000') pyautogui.typewrite(PIN_passwd) time.sleep(1) pyautogui.press('enter') logger.info("") logger.info('PIN password input success, start sleep...') time.sleep(10) logger.info('PIN password input success, sleep end.') win = None for i in range(0, 10): win = pyautogui.getWindow('Windows Security') logger.info('Check PIN password whether is correct ? [%s]' % (win)) if win == None: #print "cannot find Windows Security dialog" logger.info('PIN password is correct.') time.sleep(1) continue elif win != None: os.system("taskkill /F /IM iexplorer.exe") time.sleep(1) logger.info('PIN password is not correct.') return 1001 logger.info("") d1, h1 = pyautogui.position() logger.info('current mouse w-d is [%d - %d].' % (d1, h1)) #print resourcetype resourcex = citrix_receiver_desktops_x resourcey = citrix_receiver_desktops_y logger.info('resourcetype is [%s] and x-y is [%d - %d].' % (resourcetype, resourcex, resourcey)) pyautogui.click(resourcex, resourcey) if resourcetype == 'desktop': logger.info('start screen search...') loc = pyautogui.locateOnScreen('desktops.png') logger.info('screen search result is [%s]' % (loc)) if loc == None: #print "Can not find icon for desktops." logger.info('Can not find icon for desktops.') if resourcex != 0: #print "click desktop when fail to find desktop" logger.info('click desktop when fail to find desktop.') pyautogui.click(resourcex, resourcey) d2, h2 = pyautogui.position() logger.info('click after, mouse w-d is [%d - %d].' % (d2, h2)) else: x, y = pyautogui.center(loc) #print x, y logger.info('desktops x and y is [%d - %d].' % (x, Y)) #print "click desktop" logger.info('click desktop.') pyautogui.click(x, y) elif resourcetype == 'apps': loc = pyautogui.locateOnScreen('apps.png') if loc == None: #print "Cannot find icon for apps." logger.info('Cannot find icon for apps.') if resourcex != 0: pyautogui.click(resourcex, resourcey) else: x, y = pyautogui.center(loc) #print x,y logger.info('apps x and y is [%d - %d].' % (x, Y)) pyautogui.click(x, y) else: logger.info('Please enter desktop or apps as the resource type.') raise Exception("Please enter desktop or apps as the resource type.") logger.info('Change to Destops or favorites success, start sleep...') time.sleep(5) logger.info('Change to Destops or favorites success, sleep end.') # launch the app_name logger.info('type app name is [%s].' % (app_name)) pyautogui.typewrite(app_name, interval=0.5) for i in range(2): logger.info('press tab.') pyautogui.press('tab') time.sleep(0.1) logger.info('press enter.') pyautogui.press('enter') time.sleep(10) logger.info("") if testType != 3: #print "set receiver to foreground" logger.info('set receiver to foreground.') #win.set_foreground() time.sleep(2) win = pyautogui.getWindow('Citrix Receiver') if win != None: logger.info('getWindow Citrix Receiver success.') win.set_foreground() time.sleep(1) pyautogui.keyDown('alt') pyautogui.press('f4') pyautogui.keyUp('alt') else: logger.info('Do not close IE, because of need testing reconnect.') time.sleep(proc_wait_time) logger.info("") ret = 2000 win = None for i in range(0, 10): #win = pyautogui.getWindow('rh73demo - Desktop Viewer') win = pyautogui.getWindow(VDA_name) if win == None: #print "can not find desktop session" logger.info('can not find [%s] session.' % (VDA_name)) ret += 1 time.sleep(1) continue elif win != None: #print "find desktop session" logger.info('find desktop session.') win.set_foreground() time.sleep(5) logger.info('set foucus desktop session finished.') xn = vda_pin_center_x yn = vda_pin_center_y logger.info('center X-Y of windows is [%d - %d].' % (int(xn), int(yn))) #pyautogui.click(xn,yn) d1, h1 = pyautogui.position() logger.info('current mouse w-d is [%d - %d].' % (d1, h1)) #d5,h5 = pyautogui.position() #logger.info('new mouse X-Y is [%d - %d].' %(d5, h5)) time.sleep(0.1) #pyautogui.press('tab') logger.info('press tab keyboard change to PIN.') time.sleep(0.1) xn = vda_pin_passwd_x yn = vda_pin_passwd_y pyautogui.click(xn, yn) pyautogui.typewrite(PIN_passwd) logger.info('input PIN password.') time.sleep(0.1) xn = vda_pin_ok_button_x yn = vda_pin_ok_button_y pyautogui.click(xn, yn) #pyautogui.keyDown('tab') pyautogui.keyUp('tab') logger.info('press tab keyboard change to OK.') time.sleep(0.1) #pyautogui.press('enter') logger.info('press enter keyboard change to finish.') logger.info('current result is [%d].' % (ret)) ret = 0 time.sleep(proc_wait_time) logger.info("") return ret logger.info("") return 0
def getCoords(): x, y = gui.position() x = x - x_pad y = y - y_pad print(x, y)
def reconnect_session(resourcetype, app_name, ddc_url, VDA_name, PIN_passwd): global citrix_receiver_desktops_x, citrix_receiver_desktops_y global vda_pin_center_x, vda_pin_center_y global vda_pin_passwd_x, vda_pin_passwd_y global vda_pin_ok_button_x, vda_pin_ok_button_y global proc_wait_time, opt_wait_time logger.info("") logger.info("[Reconnect_session]:") logger.info( "********************************************************************************************" ) logger.info('citrix_receiver_desktops_x : %d' % (citrix_receiver_desktops_x)) logger.info('citrix_receiver_desktops_y : %d' % (citrix_receiver_desktops_y)) logger.info('vda_pin_center_x : %d' % (vda_pin_center_x)) logger.info('vda_pin_center_y : %d' % (vda_pin_center_y)) logger.info('vda_pin_passwd_x : %d' % (vda_pin_passwd_x)) logger.info('vda_pin_passwd_y : %d' % (vda_pin_passwd_y)) logger.info('vda_pin_ok_button_x : %d' % (vda_pin_ok_button_x)) logger.info('vda_pin_ok_button_y : %d' % (vda_pin_ok_button_y)) logger.info("") logger.info('proc_wait_time : %d' % (proc_wait_time)) logger.info('opt_wait_time : %d' % (opt_wait_time)) logger.info( "********************************************************************************************" ) logger.info("") status = 0 logger.info('Resource type is [%s] and app_name is [%s].' % (resourcetype, app_name)) logger.info('##### reconnect start ...') win = None win = pyautogui.getWindow('Citrix Receiver') if win != None: logger.info('getWindow Citrix Receiver success.') win.set_foreground() else: logger.info('getWindow Citrix Receiver failed.') return 5 logger.info("") #print resourcetype resourcex = citrix_receiver_desktops_x resourcey = citrix_receiver_desktops_y logger.info('resourcetype is [%s] and x-y is [%d - %d].' % (resourcetype, resourcex, resourcey)) pyautogui.click(resourcex, resourcey) if resourcetype == 'desktop': logger.info('start screen search...') loc = pyautogui.locateOnScreen('desktops.png') logger.info('screen search result is [%s]' % (loc)) if loc == None: #print "Can not find icon for desktops." logger.info('Can not find icon for desktops.') if resourcex != 0: #print "click desktop when fail to find desktop" logger.info('click desktop when fail to find desktop.') pyautogui.click(resourcex, resourcey) d2, h2 = pyautogui.position() logger.info('click after, mouse w-d is [%d - %d].' % (d2, h2)) else: x, y = pyautogui.center(loc) #print x, y logger.info('desktops x and y is [%d - %d].' % (x, Y)) #print "click desktop" logger.info('click desktop.') pyautogui.click(x, y) elif resourcetype == 'apps': loc = pyautogui.locateOnScreen('apps.png') if loc == None: #print "Cannot find icon for apps." logger.info('Cannot find icon for apps.') if resourcex != 0: pyautogui.click(resourcex, resourcey) else: x, y = pyautogui.center(loc) #print x,y logger.info('apps x and y is [%d - %d].' % (x, Y)) pyautogui.click(x, y) else: logger.info('Please enter desktop or apps as the resource type.') raise Exception("Please enter desktop or apps as the resource type.") logger.info('Change to Destops or favorites success, start sleep...') time.sleep(5) logger.info('Change to Destops or favorites success, sleep end.') logger.info("") # launch the app_name logger.info('type app_name is [%s].' % (app_name)) pyautogui.typewrite(app_name, interval=0.5) for i in range(2): #print "press tab" logger.info('press tab.') pyautogui.press('tab') time.sleep(0.1) #print "press enter" logger.info('press enter.') pyautogui.press('enter') time.sleep(10) logger.info("") win1 = None for i in range(0, 20): #win = pyautogui.getWindow('rh73demo - Desktop Viewer') win1 = pyautogui.getWindow(VDA_name) if win1 == None: #print "can not find desktop session" logger.info('Reconnect can not find [%s] session.' % (VDA_name)) win2 = None win2 = pyautogui.getWindow('Cannot start destop') if win2 != None: win2.set_foreground() pyautogui.press('enter') logger.info("") logger.info("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") logger.info("") #pyautogui.press('enter') time.sleep(0.1) win.set_foreground() pyautogui.click(resourcex, resourcey) pyautogui.typewrite(app_name, interval=0.5) for j in range(2): #print "press tab" logger.info('press tab.') pyautogui.press('tab') time.sleep(0.2) pyautogui.press('enter') time.sleep(5) continue elif win1 != None: break logger.info("") if win1 == None: logger.info('reconnet and re-open [%s] session linuxVDA is failed.' % (VDA_name)) return 4 logger.info("") #print "set receiver to foreground" logger.info('set receiver to foreground.') win.set_foreground() time.sleep(2) win = pyautogui.getWindow('Citrix Receiver') if win != None: logger.info('getWindow Citrix Receiver success.') win.set_foreground() time.sleep(1) pyautogui.keyDown('alt') pyautogui.press('f4') pyautogui.keyUp('alt') time.sleep(proc_wait_time) logger.info("") ret = 2000 win = None for i in range(0, 10): #win = pyautogui.getWindow('rh73demo - Desktop Viewer') win = pyautogui.getWindow(VDA_name) if win == None: #print "can not find desktop session" logger.info('can not find [%s] session.' % (VDA_name)) ret += 1 time.sleep(1) continue elif win != None: #print "find desktop session" logger.info('find desktop session.') win.set_foreground() time.sleep(5) logger.info('set foucus desktop session finished.') xn = vda_pin_center_x yn = vda_pin_center_y logger.info('center X-Y of windows is [%d - %d].' % (int(xn), int(yn))) time.sleep(0.1) #pyautogui.press('tab') logger.info('press tab keyboard change to PIN.') time.sleep(0.1) xn = vda_pin_passwd_x yn = vda_pin_passwd_y pyautogui.click(xn, yn) pyautogui.typewrite(PIN_passwd) logger.info('input PIN password.') time.sleep(0.1) xn = vda_pin_ok_button_x yn = vda_pin_ok_button_y pyautogui.click(xn, yn) #pyautogui.keyDown('tab') pyautogui.keyUp('tab') logger.info('press tab keyboard change to OK.') time.sleep(0.1) #pyautogui.press('enter') logger.info('press enter keyboard change to finish.') logger.info('current result is [%d].' % (ret)) ret = 0 logger.info("") return ret logger.info("") return 0
def __test(): print(getcwd() + "\\shares\\test.jpg") print(gui.position()) gui.click(271, 529) gui.typewrite(getcwd() + "\\shares\\test.jpg") gui.typewrite(["enter"])
steps = [] for points in locations: steps = [] turtle.clear() writeonscreen(turtle.position(), "Press Space for next point") ans = None x = points[0] y = points[1] turtle.up() turtle.goto(x, y) turtle.down() turtle.dot(30) turtle.up() writeonscreen(turtle.position(), "Press Space when you are done") mouse_x, mouse_y = pyautogui.position() if mouse_y <= h and mouse_x >= w: mouse_x += float(first[0]) mouse_y += float(first[1]) elif mouse_y <= h and mouse_x <= w: mouse_x += float(second[0]) mouse_y += float(second[1]) elif mouse_y >= h and mouse_x <= w: mouse_x += float(third[0]) mouse_y += float(third[1]) elif mouse_y >= h and mouse_x >= w: mouse_x += float(fourth[0]) mouse_y += float(fourth[1]) if mouse_y < 0: mouse_y = 0
import sys import time, sys import pyautogui ncolr = '\x1b[0m' colr = '\x1b[6;31m' while True: crnt_pos = pyautogui.position() sys.stdout.write("\r" + ncolr + "[*] Mouse current X coordinates:" + colr + str(crnt_pos[0]) + ncolr + " and Y coordinates:" + colr + str(crnt_pos[1]) + ncolr) sys.stdout.flush()
def noneff(l, t, w, h, loc, ti): global imin global f global inow global p global ton global sc global pa global wh de = {} dek = 0 ac = 0 while True: if f == 0: inow += 1 time.sleep(1) if ac > 0: #print('pl',inow,du) if inow == du: ac = 0 #print(ac) for i in de.values(): x, y = i pg.click(x, y) de = {} if inow - 1 == imin: imin += ti try: #print(p) im1 = pg.screenshot(region=(l, t, w, h)) times = datetime.now().strftime('%H.%M') floc = loc + "\\{0}ss{1}.png".format(date, times) im1.save(floc) p -= 1 if p == 0: #print(p) pg.alert('Task ending.\nThank You!', 'AutoSS') break except: pg.alert( 'Screenshot cant be saved: Storage location not found', 'AutoSS') else: c = pg.confirm('AutoSS paused', 'AutoSS', buttons=('Resume', 'Show details', 'Reset interval time', 'Reset ON_time', 'Reconfigure size', 'Reconfigure Path', 'clk sc', 'End')) if c == 'Resume': f -= 1 elif c == 'Reset interval time': imin = imin - ti ti = fti() imin = imin + ti p = po(ton, ti) f -= 1 elif c == 'Reset ON_time': ton = fton() p = po(ton, ti) f -= 1 elif c == 'Reconfigure size': l, t, w, h = size() f -= 1 elif c == 'Reconfigure Path': loc = store(date) f -= 1 elif c == 'Show details': pg.alert( 'Screenshots taken:{0}\n\nInterval time:{1}(Seconds)\n\nTotal ON time:{2}(Minutes)\n\nTime remaining:{3}(approx)\n\nWindow size={4}*{5}\n\nLocation:{6}' .format(sc - p, ti, ton, ton - (((sc - p) * ti) // 60), h, w, loc), 'AutoSS') f -= 1 elif c == 'clk sc': ac += 1 pg.alert( 'Move pointer to the postion where you want to click and press \'c\' to record and \'e\' to end recoring.', 'AutoSS') wh = True while wh == True: with k2.Listener(on_press=on_press) as listener: listener.join() if pa == 1: [q, wt] = pg.position() de[dek] = [q, wt] dek += 1 pa -= 1 du = pg.prompt('Minutes from Now=', 'AutoSS') du = inow + (float(du) * 60) f -= 1 #print(de) elif c is None: f -= 1 else: pg.alert('Thank you!', 'AutoSS') break
import os,time import pyautogui as pag screenWidth, screenHeight = pag.size() currentMouseX, currentMouseY = pag.position() print(screenWidth, screenHeight) print(currentMouseX,currentMouseY)
import pyautogui while True: screenWidth, screenHeight = pyautogui.size() #获取屏幕的尺寸 x,y = pyautogui.position() #获取当前鼠标的位置 print("[!]当前鼠标坐标: ",end='\r') print("[!]当前鼠标坐标:%s , %s"%(x,y),end='\r')
import pyautogui as g import time import datetime import os def record(): now = datetime.datetime.now().strftime("%Y-%m-%d_%H_%M_%S") #print(now) command = '.\\ffmpeg\\bin\\ffmpeg.exe -f gdigrab -i desktop -t 30 .\\record\\{}.mpg -loglevel quiet'.format( now) #os.system(command) x = os.popen(command, 'r', 1) time.sleep(30) print('x', x) x0 = 1 y0 = 1 while True: x, y = g.position() print(x, y) if x == x0 and y == y0: print('same') else: print('mouse moved') record() time.sleep(1) x0 = x y0 = y
def mouse_position(): return pyautogui.position()
# -*- coding: utf-8 -*- """ Created on Tue Nov 5 11:56:42 2019 @author: PranavM """ import pyautogui width, height = pyautogui.size() "Controlling the Mouse" pyautogui.position() pyautogui.moveTo(10, 10) pyautogui.moveTo(10, 10, duration=5) pyautogui.moveRel(500, 0) #moves the mouse relative to the current position pyautogui.displayMousePosition( ) # to check the position of the mouse at the moment. However, it is better to use it in CMD "Controlling the Keeyboard" pyautogui.click() pyautogui.typewrite(('Hello World')) from tkinter import * root = Tk() topframe = frame(root) topframe.pack() bottomframe = frame(root) bottomframe.pack(side=BOTTOM)
# pip install pyautogui # https://pyautogui.readthedocs.io/en/latest/ import pyautogui # Get the size of the primary monitor. screenWidth, screenHeight = pyautogui.size() print(screenWidth, screenHeight) # Get the XY position of the mouse. currentMouseX, currentMouseY = pyautogui.position() print(currentMouseX, currentMouseY) # --- mouse --- # Move the mouse to XY coordinates. # pyautogui.moveTo(100, 150) # Click the mouse. # pyautogui.click() # Move the mouse to XY coordinates and click it. # pyautogui.click(100, 200) # Find where button.png appears on the screen and click it. # pyautogui.click('button.png') # Move mouse 10 pixels down from its current position. # pyautogui.move(0, 10) # Double click the mouse.