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 mouse_scroll(value_scroll): threshold = 15 limiter = 0.015 if value_scroll < -threshold: final_value_scroll = int(limiter * (-value_scroll + threshold)) mouse.scroll(0, final_value_scroll) elif value_scroll > threshold: final_value_scroll = int(limiter * (-value_scroll - threshold)) mouse.scroll(0, final_value_scroll) else: pass
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
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 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 scroll(times): mouse.scroll(0,times)
def mscroll(x, y): mouse.scroll(x, y) print('mouse scroll')
move_left) == GPIO.HIGH: # if move left button is pressed keyboard.press('a') keyboard.release('a') if GPIO.input( inventory ) == GPIO.HIGH: # If inventory button is pressed | If double-pressed, will open esacpe menu inven_start_time = datetime.now() keyboard.press('e') if inven_start_time - datetime.now() <= 0.5: keyboard.press(keyboard.Key.escape) keyboard.release(keyboard.Key.escape) if GPIO.input( hotbar) == GPIO.HIGH: # Will scroll through items to the right mouse.scroll(0, 1) if GPIO.input( jump ) == GPIO.HIGH: # Will make player jump | If double clicked, player drops an item jump_start_time = datetime.now() keyboard.press(keyboard.Key.space) keyboard.release(keyboard.Key.space) if jump_start_time - datetime.now() <= 0.5: keyboard.press('q') keyboard.release('q') # This will send the right keypresses to another computer. # That other computer will then actually press the keys. # That way, I will get better Minecraft performance. # This can be turned off by setting send_press_mode to False
def scrollCtl(vertical: int, horizontal: int = 0): mouse.scroll(horizontal, vertical)
def replayEdit1(file_name): global APP screen_width = APP.winfo_screenwidth() #this function is irrelevant for the current build. But I'm hopeful that there are ways to auto speedup recordings on replay screen_height = APP.winfo_screenheight() #or at least, edit recordings. Like, if you want to speed up a segment you should be able to with a slider or dial or something 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() fast_instruction_list = [] 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])) screenshot_coord = askForScreenshot() fast_instruction_list.append(screenshot_coord) fast_instruction_list.append(row) mouse.press(eval(row[2])) except: print(row[2]) screenshot_coord = askForScreenshot() fast_instruction_list.append(screenshot_coord) fast_instruction_list.append(row) keyboard.press(checkBut(row[2])) if row[3] == 'False': try: print(eval(row[2]))# should save file name of screenshot fast_instruction_list.append(row) mouse.release(eval(row[2])) except: print(row[2]) fast_instruction_list.append(row) 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]) df = pandas.DataFrame(fast_instruction_list) df.to_csv(file_name + 'FAST.csv') homeReset()
def safeReplay1(file_name): global APP #you can ignore this function, its never called 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) 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]) #this is just another way to figure out if a continue prompt should be shown except: #but its never called in the current build. Just here because its a way to forward reference your rows, which could be useful for auto speedup 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) except: pass time.sleep(row[-1])
def safeReplay(file_name): screen_width = APP.winfo_screenwidth() #this is the function called when you've toggled into safe mode and you hit replay screen_height = APP.winfo_screenheight() #first we load in your current screen dimensions different_screen = False instruction_list = [] df = pandas.read_csv(file_name) #this is the file you selected for replay df_screen_width = df['X_loc'].iloc[0] df_screen_height = df['Y_loc'].iloc[0] df_screen_width = typeToInt(df_screen_width) #these are the screen dimensions read in from the loaded DataFrame you chose 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 #now we check if the csv you're replaying has different screen dimensions print('Calculating different screen dimensions') instruction_list = df['INSTRUCTION'].to_list() mouse = Controller() #here we're using pynput to create Controller() and KeyboardController() objects keyboard = KeyboardController() safe_instruction_list = [] for row in instruction_list[2:-2]: #we need this here, check your csv to see why literal_row = literal_eval(row) #this turns the INSTRUCTION column string entry back into a list, because csv files can't denote something as a python list x = literal_row[0] y = literal_row[1] #loading in mouse coordinates if different_screen == True: try: x = int(round(width_ratio * float(row[0]))) #here, if the screen is different, we preprocess the INSTRUCTION column to fit your screen y = int(round(height_ratio * float(row[1]))) except: pass else: try: x = int(x) #otherwise, we can just use the INSTRUCTION list as is y = int(y) except: pass btn = literal_row[2] boolean = literal_row[3] time_sleep = literal_row[4] #loading in various other values, all from the INSTRUCTION column of the DataFrame you selected safe_instruction_list.append([x,y,btn,boolean,time_sleep]) #now, another list of these rows but simply adjusted for your screen dimensions prompts = [] for row in safe_instruction_list: info_list = safer(row,safe_instruction_list) #here we pass in the row and the list the row came from, this function will usually return that no prompt is needed prompts.append(info_list) for row in prompts: if row != ('no prompt') and (prompts[prompts.index(row)-1] == 'no prompt') : #but, if there's an upcoming event, then the function safer() returns all the information neccessary to trigger a prompt just before the event index = safe_instruction_list.index(row[0]) #above we check if the previous row == 'no prompt' because this solves a bug where prompts would be triggered consecutively safe_instruction_list.insert(index,row[1]) #here, importantly, we insert into our new instruction list our prompts. There should be as many prompts as there are events else: pass for row in safe_instruction_list: print(row) for row in safe_instruction_list: if row[0] == 'continue prompt': #so now, if our instruction list includes an event, the preceeding row will trigger this line True decision = listenForCommand(row[1]) #and now, we pass in a list of the buttons about to be pressed to this function, which will prompt the user to continue if decision == True: pass #the user makes a decision, to either continue elif decision == False: homeReset() #or, they can simply reset to home screen if they don't trust what button is about to be pressed print('Exiting') return None print('Proceeding to the next row') #if there's no continue prompt, we proceed below. If there was a continue prompt and the user prompted to continue, we proceed below if row[0] != 'continue prompt': #if a row has no events, we can continue below and go about our business. Everything below is made to communicate with the pynput module try: mouse.position = row[0], row[1] #here we move the mouse except: pass if row[3] == 'True': #row[3] hold either True, False, or a placeholder. True means a button should be pressed, False a button released, and the placeholder means no buttons did anything 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]) #and here we sleep. This code where we communicate with the pynput module is present elsewhere in this script else: pass
def mouse_scroll(self, content): # 鼠标滚轮 Scrolled,x|y mouse = pynput.mouse.Controller() x = content.split("|")[0] y = content.split("|")[1] mouse.scroll(int(x), int(y))
def scroll_end(): mouse.scroll(0, -50) time.sleep(1)
def scroll_down(): mouse.scroll(0, -1) time.sleep(1)