def run(self): while True: pydirectinput.move(1,1) pydirectinput.click(self.x,self.y) time.sleep(0.2) for move in range(642): pydirectinput.move(1,0) #For harvesting pydirectinput.keyDown("f") pydirectinput.keyUp("f") for move in range(316): pydirectinput.move(-2,0) pydirectinput.mouseDown() pass pydirectinput.mouseUp() pydirectinput.keyDown("s") time.sleep(0.1) pydirectinput.keyUp("s") time.sleep(0.5) print("Complete") pass
def middle_click_software(self): """ Even pydirectinput cant click normally. This is a work-around that actually clicks in the area the cursor was moved. """ self.mouse_alt_tab() pydirectinput.click(button="middle")
def accept(self): #1270 | 690 time.sleep(self.delay) time.sleep(0.01) pyautogui.click(self.display_vars['accept_button_x'], self.display_vars['accept_button_y'])
async def on_message(message): if str(message.channel) == 'pc-control': message.content = message.content.lower() if message.content in KEYS: control.keyDown(message.content) sleep(0.4) control.keyUp(message.content) else: if message.content == 'mup': control.move(0, -200) if message.content == 'mdown': control.move(0, 200) if message.content == 'mleft': control.move(-200, 0) if message.content == 'mright': control.move(200, 0) if message.content == 'm1': control.click(button='left') if message.content == 'm2': control.click(button='right') if message.content.startswith('say'): keyboard.type(message.content[4:]) await message.delete()
def left_click_software(self, do_click: bool = True): """ Even pydirectinput cant click normally. This is a work-around that actually clicks in the area the cursor was moved. """ self.mouse_alt_tab() if do_click: pydirectinput.click()
def Shoot(mid_x, mid_y): x = int(mid_x * width) #y = int(mid_y*height) y = int(mid_y * height + height / 9) print(x, y) print(pydirectinput.position()) pydirectinput.move(x - 428, y - 267) pydirectinput.click()
def Usun(self, el): a = self.aktualne[el] tak = None while tak == None: pydirectinput.rightClick(self.komorki[0] + a[0], self.komorki[1] + a[1]) tak = pyautogui.locateOnScreen("Tak.png",region = (self.okno[0], self.okno[1], self.okno[0] + self.okno[2], self.okno[1] + self.okno[3]),confidence=0.9) time.sleep(0.1) pydirectinput.click(tak[0] + int(tak[2]/2), tak[1] + int(tak[3]/2)) time.sleep(0.1) self.Dodaj()
def clicks_and_typing(): pydirectinput.moveTo(500, 300) time.sleep(1) pydirectinput.click(500, 400) pydirectinput.keyDown('g') time.sleep(0.05) pydirectinput.keyUp('g') time.sleep(0.05) pydirectinput.press(['c', 'v', 't']) time.sleep(0.05) pydirectinput.typewrite('myword')
def clickRelativeImgBotRight(loca, disW, disH): if loca != None: R = random.randint(2, 8) C = random.randint(2, 7) pyautogui.moveTo(loca[0] + loca[2] + disW + R, loca[1] + loca[3] + disH + C, duration=0.1) pydirectinput.click() return True else: return False
def click(loca): if loca != None: R = random.randint(2, 8) C = random.randint(2, 7) pyautogui.moveTo(loca[0] + loca[2] // R, loca[1] + loca[3] // C, duration=0.1) pydirectinput.click() return True else: return False
def click(x, y, speed=.5, seconds=1): time.sleep(speed) pydirectinput.moveTo(x, y, 0.01) time.sleep(0.01) pydirectinput.moveTo(x - 5, y - 5, 0.01) time.sleep(0.01) pydirectinput.moveTo(x + 5, y + 5, 0.01) time.sleep(0.01) pydirectinput.moveTo(x - 5, y + 5, 0.01) time.sleep(0.01) pydirectinput.click(x=x, y=y, duration=seconds) print('Clicked ', (x, y))
def click(x, y): print('jalan1') ctypes.windll.user32.SetCursorPos(x, y) time.sleep(1) # pyautogui.click() # win32api.SetCursorPos((x,y)) # win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0) # time.sleep(0.1) # win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0) # win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0) # time.sleep(0.1) # win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0) pydirectinput.click()
def move_player(self): if self.point.current_status == 0: if self.mouse_mapping == "Hold Mouse Down": pydirectinput.mouseDown() # pydirectinput.keyDown('m') elif self.mouse_mapping == "Click": pydirectinput.click() elif self.mouse_mapping == "Double Click": pydirectinput.doubleClick() else: print(self.mouse_mapping, " is not recognized") else: pydirectinput.mouseUp()
def autoClick(button="left"): with open(os.getcwd() + "\\temp\\autoClick", "w+") as autoClickFile: autoClickEnabled = bool(autoClickFile.read()) if autoClickEnabled: autoClickFile.write("False") autoClickEnabled = False else: autoClickFile.write("True") autoClickEnabled = True while autoClickEnabled: pdi.click(button=button)
def play_actions(filename): # Read the file script_dir = os.path.dirname(__file__) filepath = os.path.join(script_dir, 'recordings', filename) with open(filepath, 'r') as jsonfile: # parse the json data = json.load(jsonfile) # loop over each action # Because we are not waiting any time before executing the first action, any delay before the initial # action is recorded will not be reflected in the playback. for index, action in enumerate(data): action_start_time = time() # look for escape input to exit if action['button'] == 'Key.esc': break # perform the action if action['type'] == 'keyDown': key = convert_key(action['button']) pydirectinput.keyDown(key) print("keyDown on {}".format(key)) elif action['type'] == 'keyUp': key = convert_key(action['button']) pydirectinput.keyUp(key) print("keyUp on {}".format(key)) elif action['type'] == 'click': pydirectinput.click(action['pos'][0], action['pos'][1], duration=0.25) print("click on {}".format(action['pos'])) # then sleep until next action should occur try: next_action = data[index + 1] except IndexError: # this was the last action in the list break elapsed_time = next_action['time'] - action['time'] # if elapsed_time is negative, that means our actions are not ordered correctly. throw an error if elapsed_time < 0: raise Exception('Unexpected action ordering.') # adjust elapsed_time to account for our code taking time to run elapsed_time -= (time() - action_start_time) if elapsed_time < 0: elapsed_time = 0 print('sleeping for {}'.format(elapsed_time)) sleep(elapsed_time)
def DodajDoBinga(self, el): a = self.aktualne[el] flaga = 0 licznik = 0 while flaga == 0: pydirectinput.click(self.komorki[0] + a[0], self.komorki[1] + a[1]) b = pyautogui.locateOnScreen(f"{el}.png",region = (self.okno[0], self.okno[1], self.okno[0] + self.okno[2], self.okno[1] + self.okno[3]),confidence=0.88) time.sleep(0.1) try: if math.fabs(self.komorki[1] + a[1]- b[1]) >= 50: flaga = 1 except: licznik+=1 if licznik == 2: flaga = 1
def talk_with_npc(): global nx, ny sec = 0.05 pydirectinput.click(nx, ny) time.sleep(sec) pydirectinput.press('down') time.sleep(0.05) for i in range(5): pydirectinput.press('b') time.sleep(0.05) pydirectinput.press('right') time.sleep(0.05) for i in range(2): pydirectinput.press('enter') time.sleep(0.05)
def execute_clicks(matrix, targets, offset_matrix_x, offset_matrix_y): pydirectinput.move(-10000, -10000, relative=True) last_position = [0, 0] for target in targets: matrix_target = matrix[target[1]][target[0]] # We get the target coordinates in the space of the cut sub-image and need to calculate screen coordinates position_x = round(matrix_target.position[0] + offset_matrix_x) position_y = round(matrix_target.position[1] + offset_matrix_y) # Calculate the difference to the last position since we can't use absolute coordinates relative_x = position_x - last_position[0] relative_y = position_y - last_position[1] pydirectinput.moveRel(relative_x, relative_y, relative=True) pydirectinput.click() last_position = [position_x, position_y]
def play_game(self): piece = Piece(self.new_piece) decision, pos = self.tetris.find_first(piece, self.dictdump) paint_c = 32 if decision == 1: self.tetris.insert_piece(pos[0], pos[1], piece) if self.tetris.verify_end(): self.end = True mouse_x = 15 + paint_c*pos[1] + self.PUZZLE_WINDOW_POSITION[0] + self.wincap.offset_x mouse_y = 15 + paint_c*pos[0] + self.PUZZLE_WINDOW_POSITION[1] + self.wincap.offset_y pydirectinput.click(mouse_x, mouse_y) return None if decision == 2: return None possibilites = self.tetris.find_possibles(piece) pices_count = 0 for i in range(1,7): if i != piece.piece_type: possis = self.tetris.find_possibles(Piece(i)) if len(possis): pices_count += 1 if piece.piece_type == 1 and pices_count != 0: possibilites = [i for i in possibilites if self.tetris.verify_isolated(i[0], i[1])] if len(possibilites): a = self.tetris.choose_better(piece, possibilites) self.tetris.insert_piece(a[0], a[1], piece) if self.tetris.verify_end(): self.end = True mouse_x = 15 + paint_c*a[1] + self.PUZZLE_WINDOW_POSITION[0] + self.wincap.offset_x mouse_y = 15 + paint_c*a[0] + self.PUZZLE_WINDOW_POSITION[1] + self.wincap.offset_y pydirectinput.click(mouse_x, mouse_y) return True return None
def general(w, h): if clickWhenSeeRegionS(['../simple/fabaozhu.png', '../simple/fabao2.png'], 0, 0, w, h): pass if hasImgsRegion(['../simple/zhandou.png', '../simple/zhandou2.png'], 0, 0, w, h): print('sleep...zzz') time.sleep(1) return clickWhenSeeRegion('../simple/shouyao.png', 0, 0, w, h) if clickWhenSeeRegion('../simple/jixu.png', 0, 0, w, h): tc = 10 while not hasImgsRegion([ '../simple/danren.png', '../simple/yaopo.png', '../simple/kaishixiulian.png', '../simple/tiaozhan.png' ], 0, 0, w, h) and tc > 0: clickWhenSeeRegion('../simple/jixu.png', 0, 0, w, h) print('jixu count down: ' + str(tc)) tc -= 1 if clickWhenSeeRegionS([ '../simple/qingyi.png', '../simple/qingyi4.png', '../simple/qingyi2.png', '../simple/qingyi3.png' ], 0, 0, w, h): time.sleep(0.1) pydirectinput.click() clickWhenSeeRegion('../simple/zhidaole.png', 0, 0, w, h) clickWhenSeeRegion('../simple/queren2.png', 0, 0, w, h) clickWhenSeeRegion('../simple/qianwangtiaozhan.png', 0, 0, w, h) clickWhenSeeRegion('../simple/kaishizhandou.png', 0, 0, w, h) if hasImgsRegion(['../simple/zhuzhan.png'], 0, 0, w, h): pass else: time.sleep(0.2) if hasImgsRegion(['../simple/zhuzhan.png'], 0, 0, w, h): pass else: time.sleep(0.2) clickWhenSeeRegion('../simple/querenchuzhan.png', 0, 0, w, h) time.sleep(0.5)
def Usun(self, el): self.czasik = time.time() a = self.aktualne[el] #a = pyautogui.locateOnScreen("6N.png", confidence = 0.88) tak = None licznik = 0 while tak == None: pydirectinput.rightClick(self.komorki[0] + a[0], self.komorki[1] + a[1]) #pydirectinput.rightClick(a[0] + int(a[2]/2), a[1] + int(a[3]/2)) tak = pyautogui.locateOnScreen("Tak.png",region = (self.okno[0], self.okno[1], self.okno[0] + self.okno[2], self.okno[1] + self.okno[3]),confidence=0.9) #tak = pyautogui.locateOnScreen("Tak.png", confidence = 0.8) # ZMIANA time.sleep(0.01) """ licznik+=1 if licznik == 10: break """ if time.time() - self.czasik >= 15: pydirectinput.keyDown('printscreen') time.sleep(0.2) pydirectinput.keyUp('printscreen') try: result = self.client.files_upload( channels=channel_id, initial_comment=str( "USUN " + "ILOSC GIER:" + str(self.ilosc) + " WYGRANE: " + str( self.wygrane) + " MINUT: " + str((time.time() - self.czaaas) / 60)), file=newest(), ) except Exception as e: print(e) print("OJEJ15") mp3File = "JD.mp3" playsound(mp3File) #keyboard.wait("HOME") #print("KONEIC") pydirectinput.click(tak[0] + int(tak[2]/2), tak[1] + int(tak[3]/2)) #ZMIANA time.sleep(0.03) self.Dodaj()
def Prolog(self): time.sleep(1) self.karty = None while self.karty == None: self.karty = pyautogui.locateOnScreen("Karty.png", confidence=0.8) time.sleep(0.1) pydirectinput.click(self.karty[0] + int(self.karty[2]/2), self.karty[1] + int(self.karty[3]/2)) self.start = None while self.start == None: self.start = pyautogui.locateOnScreen("Start.png", confidence=0.8) time.sleep(0.1) pydirectinput.click(self.start[0] + int(self.start[2] / 2), self.start[1] + int(self.start[3] / 2)) self.tak1 = None while self.tak1 == None: self.tak1 = pyautogui.locateOnScreen("Tak.png", confidence=0.8) time.sleep(0.1) pydirectinput.click(self.tak1[0] + int(self.tak1[2] / 2), self.tak1[1] + int(self.tak1[3] / 2)) czas2 = time.time() self.okno = None while self.okno == None: self.okno = pyautogui.locateOnScreen("Okno.png", confidence=0.8) self.dodawacz = None while self.dodawacz == None: self.dodawacz = pyautogui.locateOnScreen("Dodawacz.png", confidence=0.8) self.komorki = None while self.komorki == None: self.komorki = pyautogui.locateOnScreen("Komorki.png", confidence=0.8) print(time.time() - czas2) self.zakoncz= None while self.zakoncz == None: self.zakoncz = pyautogui.locateOnScreen("Zakoncz.png", confidence=0.8) time.sleep(0.1)
def add_friend(self, friend_name="Helen Alfcgdeggbcih Vijayvergiyasen"): # Possible exceptions - Name doesn't exist; Already added as a friend time.sleep(6) search_bar = self.driver.find_element_by_xpath(self.search_bar_xpath) search_bar.click() search_bar.send_keys(friend_name) pydirectinput.moveTo(100, 150) time.sleep(1) pydirectinput.moveTo(120, 250) pydirectinput.click() time.sleep(6) friend = self.driver.find_element_by_xpath( '/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[2]/div/div/div/div/div/div[1]/div/div/div/div/div/div[1]/div/div/div/div/div[2]/div/div[1]/h2/span/span/div/a' ) friend.click() time.sleep(3) add_friend = self.driver.find_element_by_xpath( '/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[2]/div[1]/div/div/div[3]/div/div/div/div[2]/div/div/div/div[3]/div/span/div' ) add_friend.click() time.sleep(6)
def DodajDoBinga(self, el): self.czasik = time.time() a = self.aktualne[el] flaga = 0 licznik = 0 while flaga == 0: pydirectinput.click(self.komorki[0] + a[0], self.komorki[1] + a[1]) b = pyautogui.locateOnScreen(f"{el}.png",region = (self.okno[0], self.okno[1], self.okno[0] + self.okno[2], self.okno[1] + self.okno[3]),confidence=0.88) #ZMIANA time.sleep(0.01) try: if math.fabs(self.komorki[1] + a[1]- b[1]) >= 50: flaga = 1 except: licznik+=1 if licznik == 2: #print("Nie udana flaga w dodaj bingo") flaga = 1 if time.time() - self.czasik >= 15: pydirectinput.keyDown('printscreen') time.sleep(0.2) pydirectinput.keyUp('printscreen') try: result = self.client.files_upload( channels=channel_id, initial_comment=str( "BINGO " + "ILOSC GIER:" + str(self.ilosc) + " WYGRANE: " + str( self.wygrane) + " MINUT: " + str((time.time() - self.czaaas) / 60)), file=newest(), ) except Exception as e: print(e) print("OJE16J") mp3File = "JD.mp3" playsound(mp3File)
def movePlayer(): if currentStatus != -1: if isMouseClick(keyboardParameters[currentStatus]): print("helloooooo") pydirectinput.mouseDown() else: pydirectinput.keyDown(chr(int(keyboardParameters[currentStatus]))) else: for elem in keyboardParameters: if isMouseClick(elem): pydirectinput.mouseUp() else: pydirectinput.keyUp(chr(int(elem))) if currentStatus2 == 0: pydirectinput.mouseDown() elif currentStatus2 == 1: pydirectinput.click() elif currentStatus2 == 2: pydirectinput.doubleClick() elif currentStatus2 == 3: print(currentStatus2) else: pydirectinput.mouseUp()
def set_to_begin(self, values): if values['-ENDTIMEP-']: self.end_time_enable = True try: self.end_time = int(values['-ENDTIME-']) * 60 except: self.end_time = 0 self.bait_time = values['-BAITTIME-'] self.throw_time = values['-THROWTIME-'] self.game_time = values['-STARTGAME-'] self.wincap = WindowCapture(constants.GAME_NAME) self.state = 0 self.initial_time = time() self.timer_action = time() mouse_x = int(self.FISH_WINDOW_POSITION[0] + self.wincap.offset_x + 200) mouse_y = int(self.FISH_WINDOW_POSITION[1] + self.wincap.offset_y + 200) pydirectinput.click(x=mouse_x, y=mouse_y, button='right')
def ANSYS_sim_start(modell, CWD): #Festlegung CWD für Ansys ansys_cwd = "/CWD, '%s'" % (CWD) ls = list(modell) ansys_filename_strip = "".join(ls[:len(modell) - 4]) ansys_mod = "/inp, '%s',txt" % (ansys_filename_strip) x_pos = int(MyApp.x_pos) y_pos = int(MyApp.y_pos) time.sleep(1) pydirectinput.click(x=x_pos, y=y_pos) pydirectinput.click(x=x_pos, y=y_pos) pydirectinput.press('enter') pydirectinput.click(x=x_pos, y=y_pos) pydirectinput.press('enter') pydirectinput.click(x=x_pos, y=y_pos) pyautogui.write(ansys_cwd) pydirectinput.press('enter') pyautogui.write(ansys_mod) pydirectinput.press('enter')
def clickBButton(textBox): if textBox.find("Fries") != -1: print("click fries") directinput.click(friesCordx, friesCordy) return True elif textBox.find("Burger") != -1: print("click burger") directinput.click(burgerCordx, burgerCordy) return True elif textBox.find("Cola") != -1: print("click cola") directinput.click(colaCordx, colaCordy) return True else: return False
def remove_trash(trash_list,inventory_region,inventory_tabs, number_of_tabs, player_position): for i in range(0,number_of_tabs): pydirect.click(inventory_tabs[i]['x'],inventory_tabs[i]['y']) for item in trash_list: in_inventory_item_list =list(pygui.locateAllOnScreen(f'trash\\{item}',region=inventory_region, confidence=0.9)) for item_ in in_inventory_item_list: print(item_) pydirect.click(item_.left+7,item_.top+10) pydirect.click(player_position[0]['x'],player_position[0]['y'], clicks=2, interval=0.25)
def throw_pice(self): mouse_x = int(self.PUZZLE_COMFIRM[0] + self.PUZZLE_WINDOW_POSITION[0] + self.wincap.offset_x) mouse_y = int(self.PUZZLE_COMFIRM[1] + self.PUZZLE_WINDOW_POSITION[1] + self.wincap.offset_y) pydirectinput.click(x=mouse_x, y=mouse_y, button='right')