/
gitdev
/
homm5stacks
Обзор
Документация
Войти
/
gitdev
/
homm5stacks
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
combine.py
91 строка
3 KB
gitdev
initial commit
23 май 2025, 13:24
23 май 2025, 13:24
9f8cdfd
Код
Авторство
О чём код?
from pynput import mouse, keyboard from pynput.mouse import Button, Controller import time import settings # Initialize variables x0, x1, y0, y1 = settings.BOX subsections = [] recorded_clicks = [] mouse_controller = Controller() alt_pressed = False # Function to split the screen into sections def split_section(x0, x1, y0, y1, parts=7): width = (x1 - x0) / parts subsections = [] for i in range(parts): subsection_x0 = x0 + i * width subsection_x1 = x0 + (i + 1) * width subsections.append(((subsection_x0, subsection_x1), (y0, y1))) return subsections # Check if a point (x, y) is within a section def is_within_section(x, y, section): (x_range, y_range) = section return x_range[0] <= x <= x_range[1] and y_range[0] <= y <= y_range[1] # Emulate sequential clicks in all subsections def emulate_sequential_clicks(subsections): for index, section in enumerate(subsections): click_x = (section[0][0] + section[0][1]) / 2 click_y = (section[1][0] + section[1][1]) / 2 mouse_controller.position = (click_x, click_y) mouse_controller.click(Button.left) time.sleep(0.5) if index < len(subsections)-1: mouse_controller.click(Button.left) # print(f"Emulated click in Section {index + 1} at Coordinates ({click_x}, {click_y})") # Mouse click listener function def on_click(x, y, button, pressed): global alt_pressed if pressed: # Only act on mouse down for index, section in enumerate(subsections): if is_within_section(x, y, section): print(f"Click detected in Section {index + 1}, Coordinates: {x, y}") # Check if Alt is pressed if alt_pressed: print(f"Alt-click detected in Section {index + 1}") subsections = split_section(x0, x1, y0, y1) emulate_sequential_clicks(subsections) # Record the click recorded_clicks.append({ "section": index + 1, "coordinates": (x, y) }) break # Keyboard listener functions def on_press(key): global alt_pressed if key == keyboard.Key.alt_l or key == keyboard.Key.alt_r: alt_pressed = True def on_release(key): global alt_pressed if key == keyboard.Key.alt_l or key == keyboard.Key.alt_r: alt_pressed = False if __name__=="__main__": # Start the listeners # subsections = split_section(x0, x1, y0, y1) mouse_listener = mouse.Listener(on_click=on_click) keyboard_listener = keyboard.Listener(on_press=on_press, on_release=on_release) mouse_listener.start() keyboard_listener.start() print("Mouse and keyboard listeners started. Press Alt + click to emulate sequential clicks.") try: mouse_listener.join() keyboard_listener.join() except KeyboardInterrupt: print("Listeners stopped.") print("Recorded clicks:", recorded_clicks)