def onClickRecordStart(self): command = "pgrep -l %s | awk '{print $1}'" %(self.current_game) child = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) result = child.communicate()[0].strip() game_started = False options = kCGWindowListOptionOnScreenOnly geometry = None while game_started == False: window_list = CGWindowListCopyWindowInfo(options, kCGNullWindowID) for window in window_list: pid = window['kCGWindowOwnerPID'] if str(result) == str(pid): geometry = window['kCGWindowBounds'] print geometry game_started = True applescript = os.getcwd()+'/AppleScripts/recorder.scpt' command = 'osascript '+applescript os.system(command) mouse =Controller() time.sleep(1) mouse.position = (geometry['X'], geometry['Y']+(geometry['Height']-self.height)) time.sleep(1) print 'start : ('+str(geometry['X'])+', '+str(geometry['Y']+(geometry['Height']-self.height))+')' mouse.press(Button.left) time.sleep(1) mouse.position = (geometry['X']+geometry['Width'], geometry['Y']+geometry['Height']) print 'start : ('+str(geometry['X']+geometry['Width'])+', '+str( geometry['Y']+geometry['Height'])+')' time.sleep(1) mouse.release(Button.left) time.sleep(1) mouse.position = ((2*geometry['X']+geometry['Width'])/2, (2*geometry['Y']+2*geometry['Height']-self.height)/2) time.sleep(1) mouse.click(Button.left, 1)
def handle(self, client): while True: try: message = client.recv(1024) listmessage = message.decode().split(":") mouv = listmessage[0] x = listmessage[1] y = listmessage[2] x = ''.join(c for c in x if c in digits) y = ''.join(c for c in y if c in digits) x = int(float(x)) y = int(float(y)) mouse.position = (x, y) if mouv == "Button.left": mouse.press(pynput.mouse.Button.left) mouse.release(pynput.mouse.Button.left) elif mouv == "Button.right": mouse.press(pynput.mouseButton.right) mouse.release(pynput.mouse.Button.right) print(mouv) except: index = self.clients.index(client) self.clients.remove(client) client.close() print("Client closed the connection.") break
def play(data, mouse, keyc): global live for dd in data: type= dd['type'] dur= dd['dur']/ float(speedx) time.sleep(dur) if(not live): break if(type=='mouse'): x, y = dd['pos'] btn= dd['btn'] pressed= dd['pressed'] print("X "+str(x)+" Y "+str(y)+ "delay "+str(dur)) mouse.position = (x, y) if(pressed): mouse.press(btn) else: mouse.release(btn) #mouse.click(btn) if(type=='keypress'): key= dd['key'] print("Keypress "+str(key)) keyc.press(key) if(type=='keyrelease'): key= dd['key'] print("Keyrelease "+str(key)) keyc.release(key)
def server_listen(): global serveroutput global text_box while True: put_pause=False originator=() for conn,addr in clients: conn.settimeout(0.0001) try: data=conn.recv(1024) print(data) except TimeoutException: continue if str(data, "utf-8")=="pause": put_pause=True originator = addr break if put_pause: print("click") mouse.press(Button.left) mouse.release(Button.left) serveroutput+="client {0} put pause \n".format(originator) text_box.setPlainText(serveroutput) for conn,addr in clients: if addr!=originator: conn.sendall("pause")
def selectText(x, y): from pynput.mouse import Controller, Button mouse = Controller() time.sleep(.200) mouse.position = (x, y) time.sleep(.200) mouse.press(Button.left) mouse.release(Button.left)
def put_pause_client(key): try: if(key.char=='q'): s.sendall(bytes('pause','utf-8')) mouse.press(Button.left) mouse.release(Button.left) except AttributeError: pass
def sete(): inicial = mouse.position mouse.press(pynput.mouse.Button.left) mouse.position = (inicial[0] + 30, inicial[1]) time.sleep(0.5) mouse.position = (inicial[0] + 30, inicial[1] + 50) mouse.release(pynput.mouse.Button.left) mouse.position = (inicial[0] + 40, inicial[1])
def mouseClick(timeModifier = 1): newTime = 0 try: for i in log1.clickLogs: sleep((i[3]-newTime)*timeModifier) if i[2] == 'Pressed': mouse.press(i[1]) else: mouse.release(i[1]) newTime = i[3]
def replayEdit(file_name): global APP screen_width = APP.winfo_screenwidth() screen_height = APP.winfo_screenheight() different_screen = False instruction_list = [] df = pandas.read_csv(file_name) df = df[df['Mouse Drag'] != 'place'] df_screen_width = df['X_loc'].iloc[0] df_screen_height = df['Y_loc'].iloc[0] df_screen_width = typeToInt(df_screen_width) df_screen_height = typeToInt(df_screen_height) width_ratio = float(screen_width) / float(df_screen_width) height_ratio = float(screen_height) / float(df_screen_height) if width_ratio != 1.0 or height_ratio != 1.0: different_screen = True print('Calculating different screen dimensions') instruction_list = df['INSTRUCTION'].to_list() mouse = Controller() keyboard = KeyboardController() for row in instruction_list[2:]: row = literal_eval(row) print(row) try: if different_screen == True: mouse.position = int(round(width_ratio * float(row[0]))), int( round(height_ratio * float(row[1]))) else: mouse.position = int(row[0]), int(row[1]) except: pass if row[3] == 'True': try: print(eval(row[2])) mouse.press(eval(row[2])) except: print(row[2]) keyboard.press(checkBut(row[2])) if row[3] == 'False': try: print(eval(row[2])) mouse.release(eval(row[2])) except: print(row[2]) keyboard.release(checkBut(row[2])) try: dy = int(row[3]) mouse.scroll( 0, dy ) ##the scrolling part could be tested in an automated script. Get the scroll right until on a wikipedia page you get the same word copied and pasted twice except: pass time.sleep(row[-1])
def replayEdit(file_name): global APP screen_width = APP.winfo_screenwidth() screen_height = APP.winfo_screenheight() different_screen = False instruction_list = [] df = pandas.read_csv(file_name) df = df[df['Mouse Drag'] != 'place'] #this is the key line here. We're essentially eliminating all non eventful rows. The idea is to automatically speed up your recordings df_screen_width = df['X_loc'].iloc[0] #while this is a simple way of doing that, refer to the askForScreenshot() and getCorners() functions for a more complex speedup df_screen_height = df['Y_loc'].iloc[0] df_screen_width = typeToInt(df_screen_width) df_screen_height = typeToInt(df_screen_height) width_ratio = float(screen_width)/float(df_screen_width) height_ratio = float(screen_height)/float(df_screen_height) if width_ratio != 1.0 or height_ratio != 1.0: different_screen = True print('Calculating different screen dimensions') instruction_list = df['INSTRUCTION'].to_list() mouse = Controller() keyboard = KeyboardController() for row in instruction_list[2:]: row = literal_eval(row) print(row) try: if different_screen == True: #refer to replay and safeReplay() functions mouse.position = int(round(width_ratio * float(row[0]))),int(round(height_ratio * float(row[1]))) #this way is very slow if you have a different screen else: mouse.position = int(row[0]),int(row[1]) except: pass if row[3] == 'True': #this will be True on any press try: print(eval(row[2])) mouse.press(eval(row[2])) #so we try mouse, for the button in row[2] except: print(row[2]) keyboard.press(checkBut(row[2])) #if not mouse it must have been a keyboard press if row[3] == 'False': #row[3] will be 'False' on any release try: print(eval(row[2])) mouse.release(eval(row[2])) #so first, we try the button on mouse. Eval is essential here because we need a class object, not a string as the parameter except: print(row[2]) keyboard.release(checkBut(row[2])) #if the mouse release doesn't work, it must be a button release. This actually shouldn't work but it does because when you save to a csv #your pynput button objects get converted to strings try: dy = int(row[3]) mouse.scroll(0,dy) #scrolling is pretty broken. It'll work if you scroll all the way to a buffer or page limit. But it's not accurate enough to scroll wikipedia and copy and paste words except: #I used try and excepts because they're fast and readable pass time.sleep(row[-1]) #pages load at different rates, apps too. This sleeps for as long as you did during recording
def put_pause_server(key): global clients try: if(key.char=='q'): print(clients) for conn,addr in clients: print(conn.sendall(bytes('pause','utf-8'))) print("click") mouse.press(Button.left) mouse.release(Button.left) print("paused") except AttributeError: pass
def on_press(key): if key == start_stop_key: if click_thread.running: click_thread.stop_clicking() else: click_thread.start_clicking() elif key == press_key: mouse.press(Button.left) elif key == exit_press_key: mouse.release(Button.left) elif key == exit_key: click_thread.exit() listener.stop()
def client_listen(): s.settimeout(0.0001) while True: put_pause=False try: data=s.recv(1024) put_pause=str(data, "utf-8")=="pause" print(str(data, "utf-8")) except TimeoutException: print(end='') if put_pause: print("click") mouse.press(Button.left) mouse.release(Button.left)
def on_press(key): try: if key.char == ATTACK_HOTKEY: keyboard.press('a') keyboard.release('a') time.sleep(0.15) mouse.press(Button.left) time.sleep(0.05) mouse.release(Button.left) if key.char == MOVE_HOTKEY: time.sleep(0.15) mouse.press(Button.right) time.sleep(0.05) mouse.release(Button.right) except AttributeError: return True
def mainFuncionalityFast(): mouse = pynput.mouse.Controller() if widthC > 1.76 and widthC < 1.79: widthb = int(width / 2.04) heightD = int(207) mouse.position = (widthb, heightD) time.sleep(5) mouse.press(pynput.mouse.Button.left) mouse.release(pynput.mouse.Button.left) if widthC > 1.55 and widthC < 1.7: widthb = int(width / 1.73) heightD = int(207) mouse.position = (widthb, heightD) time.sleep(5) mouse.press(pynput.mouse.Button.left) mouse.release(pynput.mouse.Button.left)
def keys(): global s2 global tunnel2 k = pynput.keyboard.Controller() mouse = pynput.mouse.Controller() while True: try: size = tunnel2.recv(5) size = int.from_bytes(size, "big") p = tunnel2.recv(size) item = pickle.loads(p) ty = str(type(item)) if ty == "<class 'tuple'>" and len(item) == 2: mouse.position = (item[0], item[1]) elif ty == "<class 'pynput.keyboard._win32.KeyCode'>" or ty == "<enum 'Key'>": k.press(item) k.release(item) elif ty == "<class 'tuple'>" and len(item) == 4: mouse.position = (item[0], item[1]) if item[3]: mouse.press(item[2]) else: mouse.release(item[2]) except ConnectionResetError: s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.bind(("", 1235)) s2.listen(1) tunnel2, ipc = s2.accept() except Exception as e: print(e)
def safeReplay(file_name): screen_width = APP.winfo_screenwidth() screen_height = APP.winfo_screenheight() different_screen = False instruction_list = [] df = pandas.read_csv(file_name) df_screen_width = df['X_loc'].iloc[0] df_screen_height = df['Y_loc'].iloc[0] df_screen_width = typeToInt(df_screen_width) df_screen_height = typeToInt(df_screen_height) width_ratio = float(screen_width) / float(df_screen_width) height_ratio = float(screen_height) / float(df_screen_height) if width_ratio != 1.0 or height_ratio != 1.0: different_screen = True print('Calculating different screen dimensions') instruction_list = df['INSTRUCTION'].to_list() mouse = Controller() keyboard = KeyboardController() safe_instruction_list = [] for row in instruction_list[2:-2]: literal_row = literal_eval(row) x = literal_row[0] y = literal_row[1] if different_screen == True: try: x = int(round(width_ratio * float(row[0]))) y = int(round(height_ratio * float(row[1]))) except: pass else: try: x = int(x) y = int(y) except: pass btn = literal_row[2] boolean = literal_row[3] time_sleep = literal_row[4] safe_instruction_list.append([x, y, btn, boolean, time_sleep]) prompts = [] for row in safe_instruction_list: info_list = safer(row, safe_instruction_list) prompts.append(info_list) for row in prompts: if row != ('no prompt') and (prompts[prompts.index(row) - 1] == 'no prompt'): index = safe_instruction_list.index(row[0]) safe_instruction_list.insert(index, row[1]) else: pass for row in safe_instruction_list: print(row) for row in safe_instruction_list: if row[0] == 'continue prompt': decision = listenForCommand(row[1]) if decision == True: pass elif decision == False: homeReset() print('Exiting') return None print('Proceeding to the next row') if row[0] != 'continue prompt': try: mouse.position = row[0], row[1] except: pass if row[3] == 'True': try: mouse.press(eval(row[2])) except: keyboard.press(checkBut(row[2])) if row[3] == 'False': try: mouse.release(eval(row[2])) except: keyboard.release(checkBut(row[2])) try: dy = int(row[3]) mouse.scroll(0, dy) except: pass time.sleep(row[-1]) else: pass #go back to line 326
def mouse_click(): mouse = Controller() mouse.press(Button.left) mouse.release(Button.left)
def key3 (key1,key2,key3): with mouse.pressed(key1): with mouse.pressed(key2): mouse.press(key3) mouse.release(key3)
def keys2 (key1,key2): #two keys with mouse.pressed(key2): mouse.press(key1) mouse.release(key1)
def releasekey(keykey): mouse.release(Key.keykey)
def relaeseright(): mouse.release(Button.right)
def clickright (): mouse.press(Button.right) mouse.release(Button.right)
def clickleft (): mouse.press(Button.left) mouse.release(Button.left)
from pynput import mouse mouse = Controller() # Read pointer position print('The current pointer position is {0}'.format(mouse.position)) # Set pointer position mouse.position = (10, 20) print('Now we have moved it to {0}'.format(mouse.position)) # Move pointer relative to current position mouse.move(5, -5) # Press and release mouse.press(Button.left) mouse.release(Button.left) # Double click; this is different from pressing and releasing # twice on macOS mouse.click(Button.left, 2) # Scroll two steps down mouse.scroll(0, 2)
def safeReplay1(file_name): global APP global CONTINUE_CHECK screen_width = APP.winfo_screenwidth() screen_height = APP.winfo_screenheight() different_screen = False instruction_list = [] df = pandas.read_csv(file_name) df_screen_width = df['X_loc'].iloc[0] df_screen_height = df['Y_loc'].iloc[0] df_screen_width = typeToInt(df_screen_width) df_screen_height = typeToInt( df_screen_height ) #up here i should process instruction list, and adjust values if neccessary, and make sure there's always a mouse position width_ratio = float(screen_width) / float(df_screen_width) height_ratio = float(screen_height) / float(df_screen_height) if width_ratio != 1.0 or height_ratio != 1.0: different_screen = True print('Calculating different screen dimensions') instruction_list = df['INSTRUCTION'].to_list() mouse = Controller() keyboard = KeyboardController() for row in instruction_list[2:]: try: next_row = eval(instruction_list[instruction_list.index(row) + 1]) except: next_row = ['k', 'k', 'k', 'False'] if next_row[3] == 'True': continuePrompt(next_row[2]) decision = checkDecision(next_row[2]) if not decision: return None row = literal_eval(row) print(row) try: if different_screen == True: mouse.position = int(round(width_ratio * float(row[0]))), int( round(height_ratio * float(row[1]))) else: mouse.position = int(row[0]), int(row[1]) except: pass if row[3] == 'True': try: print(eval(row[2])) mouse.press(eval(row[2])) except: print(row[2]) keyboard.press(checkBut(row[2])) if row[3] == 'False': try: print(eval(row[2])) mouse.release(eval(row[2])) except: print(row[2]) keyboard.release(checkBut(row[2])) try: dy = int(row[3]) mouse.scroll( 0, dy ) ##the scrolling part could be tested in an automated script. Get the scroll right until on a wikipedia page you get the same word copied and pasted twice except: pass time.sleep(row[-1])
def ckck(a, b): mouse.position = (a, b) mouse.press(Button.left) mouse.release(Button.left)
def clickkey(keykey): mouse.press(Key.keykey) mouse.release(Key.keykey)
cv2.waitKey(0) cv2.destroyAllWindows() return count while (1): print(mouse.position) lista = open('lista.txt', 'r').read() lista2f = open('lista2.txt', 'a') lista2 = [] for x in lista.split('\n'): print(x) mouse.position = (750, 750) mouse.press(pynput.mouse.Button.left) time.sleep(0.03 + 0.02 * random.random()) mouse.release(pynput.mouse.Button.left) time.sleep(0.07 + 0.03 * random.random()) mouse.press(pynput.mouse.Button.left) time.sleep(0.03 + 0.02 * random.random()) mouse.release(pynput.mouse.Button.left) time.sleep(0.07 + 0.03 * random.random()) mouse.press(pynput.mouse.Button.left) time.sleep(0.03 + 0.02 * random.random()) mouse.release(pynput.mouse.Button.left) time.sleep(0.3 + 0.1 * random.random()) keyboard.type(x) time.sleep(1 + 0.1 * random.random()) lista2.append(find()) lista2f.write(str(lista2[len(lista2) - 1]) + '\n') print(lista2[len(lista2) - 1])
def mrelease(): mouse.release(pynput.mouse.Button.left) print('mouse has releae') # print(time.time()) exit(1)