def resetar(): for i in re.sub('[^0-9]', '', cortar_e_ocr((1350, 380, 50, 20))): busca_por_imagem(i) ahk = AHK(executable_path='./ahk_folder/AutoHotkeyA32.exe') ahk.mouse_move(x=1149, y=649) ahk.click(direction='down') time.sleep(0.008) ahk.click(direction='up')
class TestMouse(TestCase): def setUp(self) -> None: self.ahk = AHK() def test_mouse_move(self): x, y = self.ahk.mouse_position self.ahk.mouse_move(10, 10, relative=True) assert self.ahk.mouse_position == (x + 10, y + 10)
def uppar(): ahk = AHK(executable_path='./ahk_folder/AutoHotkeyA32.exe') while True: if re.sub('[^0-9]', '', cortar_e_ocr((930, 200, 50, 20))) != '600': ahk.mouse_move(1828, 791) ahk.click(direction='down') else: ahk.click(direction='up') break
def busca_por_imagem(name_img): pos = imagesearch(f"./data/{name_img}.JPG") img = cv2.imread(f"./data/{name_img}.JPG") size = img.shape print(size) if pos[0] != -1: ahk = AHK(executable_path='./ahk_folder/AutoHotkeyA32.exe') ahk.mouse_move(x=pos[0] + (size[1] / 2), y=pos[1] + (size[0] / 2)) ahk.click(direction='down') time.sleep(0.008) ahk.click(direction='up') else: busca_por_imagem(name_img)
class TestMouse(TestCase): def setUp(self) -> None: self.ahk = AHK() self.original_position = self.ahk.mouse_position self.notepad_process = None def tearDown(self) -> None: self.ahk.mouse_move(*self.original_position) if self.notepad_process is not None: self.notepad_process.terminate() def test_mouse_move(self): x, y = self.ahk.mouse_position self.ahk.mouse_move(10, 10, relative=True) assert self.ahk.mouse_position == (x + 10, y + 10) def test_mouse_move_absolute(self): original_x, original_y = self.original_position new_x = original_x + 10 new_y = original_y + 10 self.ahk.mouse_move(new_x, new_y) assert self.ahk.mouse_position == (new_x, new_y) def test_mouse_move_callable_speed(self): x, y = self.ahk.mouse_position self.ahk.mouse_move(10, 10, relative=True, speed=lambda: 10) assert self.ahk.mouse_position == (x + 10, y + 10) def test_mouse_drag(self): self.notepad_process = subprocess.Popen('notepad') time.sleep(0.5) notepad = self.ahk.find_window(title=b'Untitled - Notepad') win_width = notepad.width win_height = notepad.height print(*notepad.position) self.ahk.mouse_move(*notepad.position) time.sleep(1) # moving the mouse to the window position puts it in a position where it can be resized by dragging ↖ ↘ # after this, we expect the window height/width to shrink by 10px self.ahk.mouse_drag(10, 10, relative=True) assert notepad.width == win_width - 10 assert notepad.height == win_height - 10
class Controller: def __init__(self): self.mouse = AHK() self.keyboard = None #KeyboardController() def random_walk(self): offset_x = 3 offset_y = 22 center_x = (1024 + offset_x) / 2 center_y = (768 + offset_y) / 2 range = 150 x = center_x + randint(-range, range) y = center_y + randint(-range, range) self.mouse.mouse_move(x=x, y=y, speed=3, blocking=True) time.sleep(0.5) self.mouse.click(x, y) time.sleep(0.5) def atacar(self, x, y): x += 25 y += 25 print("About to attack") self.mouse.mouse_position = (x, y) time.sleep(0.2) self.mouse.click() time.sleep(5) def skill_F1(self): self.mouse.mouse_position = (235, 41) time.sleep(0.2) self.mouse.click() time.sleep(0.2) self.mouse.click()
[[2470, 1320], [2495, 1340]] ] pc_type = input("Desktop or Laptop?") if pc_type.upper() == "DESKTOP": inventory = desktop_inventory elif pc_type.upper() == "LAPTOP": # Need to add pixels for laptop inventory = 'laptop inventory' def get_random_coords(coords): random_x = randint(coords[0][0], coords[1][0]) random_y = randint(coords[0][1], coords[1][1]) return [random_x, random_y] sleep(5) for slot_coords in inventory: random_enchant_coords = get_random_coords(enchant_four) random_slot_coords = get_random_coords(slot_coords) ahk.mouse_move(random_enchant_coords[0], random_enchant_coords[1]) ahk.click() sleep(uniform(0.2, 0.5)) ahk.mouse_move(random_slot_coords[0], random_slot_coords[1]) ahk.click() sleep(uniform(1.2, 1.5))
import pyautogui from ahk import AHK import time ahk = AHK() print(f"Active window: {ahk.active_window}") print(f"Position: {ahk.active_window.rect}") print(f"Title: {ahk.active_window.title}") print(f"Windows: {ahk.windows()}") # ahk.active_window.title = "Bashash" # time.sleep(0.5) # ahk.active_window.hide() # time.sleep(0.5) # ahk.active_window.show() for w in ahk.windows(): if b"bash" in w.title: w.restore() ahk.mouse_move( x=100, y=100, blocking=True) # Blocks until mouse finishes moving (the default) ahk.mouse_move( x=150, y=150, speed=1, blocking=True) # Moves the mouse to x, y taking 'speed' seconds to move print(ahk.mouse_position) # (150, 150)
class BoardAPI: """ def __init__(self, point_top_right, point_top_left, point_bottom_right, point_bottom_left): # point format (x, y) tuple type top = point_top_right[1] bottom = point_bottom_right[1] left = point_top_left[0] right = point_top_right[0] self.point_top_right = point_top_right if (point_top_left[1] != top): point_top_left = (left, top) self.point_top_left = point_top_left if (point_bottom_right[0] != right ): point_bottom_right = (right, bottom) self.point_bottom_right = point_bottom_right if (point_bottom_left[0] != left or point_bottom_left[1] != bottom): point_bottom_left = (left, bottom) self.point_bottom_left = point_bottom_left """ def __init__(self, point_top_right, length, playing_color): self.point_top_right = point_top_right self.point_top_left = (point_top_right[0] + length, point_top_right[1]) self.point_bottom_right = (point_top_right[0], point_top_right[1] + length) self.point_bottom_left = (point_top_right[0] + length, point_top_right[1] + length) self.board = chess.Board() # to detect rival move self.previous_board_state = { 'a8': ('black', 'R'), 'b8': ('black', 'N'), 'c8': ('black', 'B'), 'd8': ('black', 'Q'), 'e8': ('black', 'K'), 'f8': ('black', 'B'), 'g8': ('black', 'N'), 'h8': ('black', 'R'), 'a7': ('black', 'P'), 'b7': ('black', 'P'), 'c7': ('black', 'P'), 'd7': ('black', 'P'), 'e7': ('black', 'P'), 'f7': ('black', 'P'), 'g7': ('black', 'P'), 'h7': ('black', 'P'), 'a6': None, 'b6': None, 'c6': None, 'd6': None, 'e6': None, 'f6': None, 'g6': None, 'h6': None, 'a5': None, 'b5': None, 'c5': None, 'd5': None, 'e5': None, 'f5': None, 'g5': None, 'h5': None, 'a4': None, 'b4': None, 'c4': None, 'd4': None, 'e4': None, 'f4': None, 'g4': None, 'h4': None, 'a3': None, 'b3': None, 'c3': None, 'd3': None, 'e3': None, 'f3': None, 'g3': None, 'h3': None, 'a2': ('white', 'P'), 'b2': ('white', 'P'), 'c2': ('white', 'P'), 'd2': ('white', 'P'), 'e2': ('white', 'P'), 'f2': ('white', 'P'), 'g2': ('white', 'P'), 'h2': ('white', 'P'), 'a1': ('white', 'R'), 'b1': ('white', 'N'), 'c1': ('white', 'B'), 'd1': ('white', 'Q'), 'e1': ('white', 'K'), 'f1': ('white', 'B'), 'g1': ('white', 'N'), 'h1': ('white', 'R') } self.playing_color = playing_color self.ahk = AHK() def init(self): self.previous_board_state = self.get_figures_pos() def get_rival_color(self): map_color = {"white": "black", "black": "white"} return map_color[self.playing_color] def get_A(self): return abs(self.point_bottom_right[1]) - abs(self.point_top_right[1]) def get_B(self): return abs(self.point_top_left[0]) - abs(self.point_top_right[0]) def get_C(self): return abs(self.point_bottom_left[1]) - abs(self.point_top_left[1]) def get_D(self): return abs(self.point_bottom_left[0]) - abs(self.point_bottom_right[0]) def save_image_of_board(self, filepath): # part of the screen im = ImageGrab.grab(bbox=(self.point_top_right[0], self.point_top_right[1], self.point_bottom_left[0], self.point_bottom_left[1])) # X1,Y1,X2,Y2 # save image file im.save(filepath) def _slice_images(self, filepath, dirpath): # white case board_coord_map_col = { 1: "8", 2: "7", 3: "6", 4: "5", 5: "4", 6: "3", 7: "2", 8: "1" } board_coord_map_row = { 1: "a", 2: "b", 3: "c", 4: "d", 5: "e", 6: "f", 7: "g", 8: "h" } # black case if (self.playing_color == "black"): board_coord_map_col = { 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8" } board_coord_map_row = { 1: "h", 2: "g", 3: "f", 4: "e", 5: "d", 6: "c", 7: "b", 8: "a" } tiles = slice(filepath, 64, 8, 8, False) result = [] for tile in tiles: filepath = dirpath filename = f"{board_coord_map_row[tile.row]}{board_coord_map_col[tile.column]}.png" fullpath = os.path.join(filepath, filename) tile.save(fullpath) result.append(fullpath) return result def get_figures_pos(self, debug=False): """[summary] returns dict with figures and possitions possitions as keys and figures as value """ result = {} with tempfile.TemporaryDirectory() as tmpdirname: filepath = os.path.join(tmpdirname, "board.png") self.save_image_of_board(filepath) tiles_pathes = self._slice_images(filepath, tmpdirname) for tile in tiles_pathes: figure = self.recognize_figure(tile) tile_location = Path(tile).stem result[tile_location] = figure if (debug): print(tmpdirname) input(f"press any button {__name__}") return result def _get_figures_pos(self, debug=True): result = {} tmpdirname = tempfile.mkdtemp() if True: filepath = os.path.join(tmpdirname, "board.png") self.save_image_of_board(filepath) tiles_pathes = self._slice_images(filepath, tmpdirname) for tile in tiles_pathes: figure = self.recognize_figure(tile) tile_location = Path(tile).stem result[tile_location] = figure if (debug): print(tmpdirname) input(f"press any button {__name__}") return result def get_board_state_fen(self, debug=False): return self.board.fen() def recognize_figure(self, filepath): # output format (1 or 2, "letter") result = None which_color = { "(248, 248, 248)": "white", # whie color "(86, 83, 82)": "black" # black color } approx_pixel_count_map = { "K": 2171, "Q": 1865, "R": 1507, "B": 1365, "N": 1677, "P": 978 } coef_map = { "K": 4.15707, "Q": 4.91825, "R": 5.98871, "B": 6.61172, "N": 5.18163, "P": 9.22801 } im = Image.open(filepath) pixels = list(im.getdata()) width, height = im.size pixels = [pixels[i] for i in range(height * width)] unique_pixels = list(set(pixels)) pixel_count = {} for pixel in unique_pixels: if (pixels.count(pixel) > 20): pixel_count[str(pixel)] = pixels.count(pixel) # create difference dict difference_dict = {} # find main color figure_color = None main_color_pixel = None for pixel in pixel_count: if pixel in which_color: figure_color = which_color[pixel] main_color_pixel = pixel if figure_color is not None: # get subtraction of main color for figure_letter in approx_pixel_count_map: # write into difference dict as differ as key and letter as value # amount_of_pixels = width * height # coefficient = amount_of_pixels / pixel_count[main_color_pixel] # difference = abs(coefficient - coef_map[figure_letter]) # difference_dict[difference] = figure_letter # working difference = abs(pixel_count[main_color_pixel] - approx_pixel_count_map[figure_letter]) difference_dict[difference] = figure_letter diff_list = list(difference_dict.keys()) diff_list.sort() print( f"recognize_figure: filepath = {filepath} diffrenece dict = ") print(difference_dict) print(f"sorted values: {diff_list}") print() figure_letter = difference_dict[diff_list[0]] result = (figure_color, figure_letter) return result def _click_on_tile(self, tile_location: str): # white case letter_map = { "a": 0, "b": 1, "c": 2, "d": 3, "e": 4, "f": 5, "g": 6, "h": 7 } number_map = { "8": 0, "7": 1, "6": 2, "5": 3, "4": 4, "3": 5, "2": 6, "1": 7 } # black case if (self.playing_color == "black"): letter_map = { "a": 7, "b": 6, "c": 5, "d": 4, "e": 3, "f": 2, "g": 1, "h": 0 } number_map = { "8": 7, "7": 6, "6": 5, "5": 4, "4": 3, "3": 2, "2": 1, "1": 0 } length = self.get_A() length_of_tile = length / 8 # init X Y values which will be added to point top right # set X to letter_sequence * width + (width/8/2) X = letter_map[tile_location[0]] * length_of_tile + (length_of_tile / 2) # set Y to number * height + (height/8/2) Y = number_map[tile_location[1]] * length_of_tile + (length_of_tile / 2) # add to point top rigth X and Y coords = (self.point_top_right[0] + X, self.point_top_right[1] + Y) print(X) print(Y) print(coords) # click with this coords on screen self.ahk.click(coords[0], coords[1]) # get rid of cursor self.ahk.mouse_move(0, 0) def move_figure_from_to(self, coords: str): """[summary] Args: coords (str): e5e1 this is an example of coords """ print(f" move_figure_from_to coords is {coords}") print(f"before:\n{self.board}") self._click_on_tile(coords[:2]) self._click_on_tile(coords[2:]) self.board.push_uci(coords) # TODO optimize this shit, if it s needed due to optimazation problem with this method self.previous_board_state = self.get_figures_pos() print(f"after:\n{self.board}") def update_board_after_rival_move(self): print("update_board_after_rival_move") print(f"before:\n{self.board}") moveuci = self.get_rivals_move() self.board.push_uci(moveuci) self.previous_board_state = self.get_figures_pos() print(f"after:\n{self.board}") def is_my_turn(self): turn_dict = {chess.BLACK: "black", chess.WHITE: "white"} return turn_dict[self.board.turn] == self.playing_color def get_rivals_move(self): # get new board state new_board_state = self.get_figures_pos() # check if it s catstling castling_tiles_map = { "white": { 'K': ['e1', 'g1'], 'Q': ['c1', 'd1'] }, "black": { 'K': ['e8', 'g8'], 'Q': ['c8', 'd8'] } } # check castling rivals tiles from King side print("get_rival_move: check for castling k side") k_side_castle = castling_tiles_map[self.get_rival_color()]['K'] if new_board_state[ k_side_castle[1]] != None and self.previous_board_state[ k_side_castle[0]] != None: first_check = new_board_state[k_side_castle[1]][ 1] == 'K' and new_board_state[k_side_castle[0]] == None second_check = self.previous_board_state[ k_side_castle[1]] == None and self.previous_board_state[ k_side_castle[0]][1] == 'K' if first_check and second_check: return ''.join(k_side_castle) print("nope this is not the case") # check castling rivals tiles from Queen side print("get_rival_move: check for castling q side") q_side_castle = castling_tiles_map[self.get_rival_color()]['Q'] if new_board_state[q_side_castle[0]] != None and new_board_state[ q_side_castle[1]] != None: first_check = new_board_state[q_side_castle[0]][ 1] == 'K' and new_board_state[q_side_castle[1]][1] == 'R' second_check = self.previous_board_state[q_side_castle[ 0]] == None and self.previous_board_state[q_side_castle[1]] if first_check and second_check: return ''.join(q_side_castle) print("this is also not the case") # else go ahead # check for en passant # get en passant fen str from board en_passant = self.board.fen().split(" ")[3] if en_passant != '-': # if on that tile is a pawn, then check where is was positions = list(new_board_state.keys()) prev_pos = None # get position, comparing new and old states, of empty tile for position in positions: # where no figure there is coords for first part existing_check = new_board_state[position] == None generic_check = new_board_state[ position] != self.previous_board_state[position] if generic_check and existing_check and en_passant[ 0] not in position: prev_pos = position logging.debug( f"Comparing En passant new board state[pos] = {new_board_state[position]} prev pos = {self.previous_board_state[position]}, pos appended = {position} " ) return position + prev_pos # concate en passant str with pawn prev pos # return this # else go ahead # compare every single position on board with new board state positions = list(new_board_state.keys()) changed_pos = [] # get position, comparing new and old states, of empty tile for position in positions: # where no figure there is coords for first part existing_check = new_board_state[position] == None generic_check = new_board_state[ position] != self.previous_board_state[position] if generic_check and existing_check: changed_pos.append(position) logging.debug( f"Comparing None new board state[pos] = {new_board_state[position]} prev pos = {self.previous_board_state[position]}, pos appended = {position} " ) # get figure that moved and new pos of this figure for position in positions: # where figure appeared there is coords for second part if (new_board_state[position] != None): color_check = new_board_state[position][ 0] == self.get_rival_color() generic_check = new_board_state[ position] != self.previous_board_state[position] if generic_check and color_check: changed_pos.append(position) logging.debug( f"Comparing figure new board state[pos] = {new_board_state[position]} prev pos = {self.previous_board_state[position]}, pos appended = {position} " ) # get two difference positions of rivals figures move = ''.join(changed_pos) if (move == ''): move = None # promotion in chess, if pawn manage to get to the other side of a board # TODO there some bug where Knight recognized as Queen in some cases # have no idea how to fix that so I jsut bodge this if self.previous_board_state[changed_pos[0]][1] != new_board_state[ changed_pos[1]][1] and self.previous_board_state[ changed_pos[0]][1] == 'P': print( f"promotion check: prev on '{changed_pos[0]}' = {self.previous_board_state[changed_pos[0]]}, new on '{changed_pos[1]}' = {new_board_state[changed_pos[1]]}" ) print(self.previous_board_state) print(new_board_state) move += new_board_state[changed_pos[1]][1].lower() return move
json.dump(p_c, f) exit() time.sleep(2) filepath = r"C:\Users\Superuser\Pictures\Saved Pictures\chess\board.png" dirpath = r"C:\Users\Superuser\Pictures\Saved Pictures\chess" #b.save_image_of_board(filepath) b._slice_images(filepath, dirpath) exit() print(b.point_top_right) print(b.point_top_left) print(b.point_bottom_right) print(b.point_bottom_left) time.sleep(2) ahk.mouse_move(x=b.point_top_left[0], y=b.point_top_left[1], speed=10, blocking=True) ahk.mouse_move(x=b.point_bottom_left[0], y=b.point_bottom_left[1], speed=10, blocking=True) ahk.mouse_move(x=b.point_top_right[0], y=b.point_top_right[1], speed=10, blocking=True) ahk.mouse_move(x=b.point_bottom_right[0], y=b.point_bottom_right[1], speed=10,
from ahk import AHK ahk = AHK(executable_path=r"C:\Program Files\AutoHotkey\AutoHotkey.exe") block = True ahk.mouse_move(x=100, y=100, speed=10, blocking=block) ahk.mouse_move(x=1000, y=100, speed=10, blocking=block) ahk.mouse_move(x=1000, y=1000, speed=10, blocking=block) ahk.mouse_move(x=100, y=1000, speed=10, blocking=block) print(ahk.mouse_position) # (100, 100)
def inventory(foo, argu1): ahk = AHK() if "active" not in target: if "tog" not in foo: if "a1" in foo: op = 2586, 589 elif "a2" in foo: op = 2664, 593 elif "a3" in foo: op = 2734, 591 elif "a4" in foo: op = 2806, 583 elif "a5" in foo: op = 2898, 583 elif "a6" in foo: op = 2950, 577 elif "a7" in foo: op = 3030, 580 elif "a8" in foo: op = 3171, 586 elif "a9" in foo: op = 3171, 586 elif "b1" in foo: op = 2591, 646 elif "b2" in foo: op = 2664, 645 elif "b3" in foo: op = 2735, 647 elif "b4" in foo: op = 2809, 645 elif "b5" in foo: op = 2880, 646 elif "b6" in foo: op = 2955, 646 elif "b7" in foo: op = 3024, 646 elif "b8" in foo: op = 3099, 647 elif "b9" in foo: op = 3168, 646 elif "c1" in foo: op = 2591, 719 elif "c2" in foo: op = 2663, 717 elif "c3" in foo: op = 2737, 717 elif "c4" in foo: op = 2806, 717 elif "c5" in foo: op = 2881, 718 elif "c6" in foo: op = 2952, 717 elif "c7" in foo: op = 3025, 717 elif "c8" in foo: op = 3096, 720 elif "c9" in foo: op = 3169, 720 else: None if argu1 == "1": po = 1 if argu1 == "2": po = 2 if argu1 == "3": po = 3 if argu1 == "4": po = 4 if argu1 == "5": po = 5 if argu1 == "6": po = 6 if argu1 == "7": po = 7 if argu1 == "8": po = 8 if argu1 == "9": po = 9 ahk.key_press('e') ahk.mouse_move(2121, 241) ahk.mouse_drag(op) ahk.key_press(str(po)) ahk.key_press('e') else: ahk.key_press('e') target.append('active') print(target) else: if "active" in target: ahk.key_press('e') target.clear() print(target)
class InputAutomator(webdriver.Ie): options = webdriver.IeOptions() user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko' options.add_argument(f'user-agent={user_agent}') options.add_argument("IgnoreZoomLevel=true") def __init__(self, *args, **kwargs): kwargs['executable_path'] = 'IEDriverServer.exe' kwargs['ie_options'] = self.options super().__init__(*args, **kwargs) self.maximize_window() self.ahk = AHK(executable_path="AutoHotkeyU64.exe") def adjust_coordinates(self, x, y): """ Adjusts document coordinates given by selenium to screen coordinates used by AHK. :param x: x coordinate (pixels) in document :param y: y coordinate (pixels) in document :return: (x_adj, y_adj) """ window_pos = self.get_window_position() browser_navigation_panel_height = self.execute_script( 'return window.outerHeight - window.innerHeight;') return x + window_pos['x'], y + window_pos[ 'y'] + browser_navigation_panel_height def move_rand(self, elem_type, elem_text, x_offset=0, y_offset=0): """ Moves mouse to a given element using a random walk path. Does not seem to make a difference. :param elem_type: one of "class", "css" or "id" :param elem_text: value of "class", "css" or "id" :param x_offset: x offset from element coordinates for final mouse position :param y_offset: y offset from element coordinates for final mouse position """ try: if elem_type == "class": out = self.find_element_by_class_name(elem_text).location elif elem_type == "css": out = self.find_element_by_css_selector(elem_text).location elif elem_type == "id": out = self.find_element_by_class_name(elem_text).location else: raise ValueError("Unknown elem_type: must be class, css or id") except (NoSuchElementException, TimeoutException, JavascriptException): return False x_final, y_final = self.adjust_coordinates(out['x'] + x_offset, out['y'] + y_offset) x0, y0 = self.ahk.mouse_position x_path, y_path = constrained_walk_2d((x0, y0), (x_final, y_final)) # Reduce points x_path = x_path[:1] + x_path[::max([len(x_path) // 50, 1])] + x_path[-1:] y_path = y_path[:1] + y_path[::max([len(y_path) // 50, 1])] + y_path[-1:] for x, y in zip(x_path, y_path): self.ahk.run_script(f"SetMouseDelay, -1\nMouseMove, {x}, {y} , 0") # self.ahk.mouse_move(x=x, y=y, blocking=True, speed=0) def move_to(self, elem_type, elem_text, x_offset=0, y_offset=0): self.maximize_window() """ Moves mouse to a given element directly. Passes reCAPTCHA. :param elem_type: one of "class", "css" or "id" :param elem_text: value of "class", "css" or "id" :param x_offset: x offset from element coordinates for final mouse position :param y_offset: y offset from element coordinates for final mouse position """ try: if elem_type == "class": out = self.find_element_by_class_name(elem_text).location elif elem_type == "css": out = self.find_element_by_css_selector(elem_text).location elif elem_type == "id": out = self.find_element_by_class_name(elem_text).location else: raise ValueError("Unknown elem_type: must be class, css or id") self.ahk.mouse_move(*self.adjust_coordinates( out['x'] + x_offset, out['y'] + y_offset), speed=10, blocking=True) return True except (NoSuchElementException, TimeoutException, JavascriptException): return False def click(self): self.ahk.click() def type(self, text): self.ahk.send_input(text) def scroll(self, direction, times): [self.ahk.mouse_wheel(direction) for i in range(times)] def wait_for(self, elem_type, elem_text, timeout=15): result = False start = time() while not result and time() - start < timeout: try: if elem_type == "class": result = self.find_element_by_class_name( elem_text).is_displayed() elif elem_type == "css": result = self.find_element_by_css_selector( elem_text).is_displayed() elif elem_type == "id": result = self.find_element_by_class_name( elem_text).is_displayed() return result except (NoSuchElementException, TimeoutException, JavascriptException): result = False sleep(0.1) if not result: print(f"Warn: Element {elem_text} not found after {timeout} sec") return result
from ahk import AHK ahk = AHK(executable_path="C:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe") print(ahk.mouse_position) # Returns a tuple of mouse coordinates (x, y) ahk.mouse_move( 100, 100, speed=10, relative=True) # Moves the mouse reletave to the current position for i in range(0, 10): ahk.key_down('z', blocking=False) # Press down (but do not release) Control key ahk.key_up('z', blocking=False) # Release the key zzzzzzzzzz