/
gitdev
/
homm5stacks
Обзор
Документация
Войти
/
gitdev
/
homm5stacks
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
split.py
156 строк
5 KB
gitdev
initial commit
23 май 2025, 13:24
23 май 2025, 13:24
9f8cdfd
Код
Авторство
О чём код?
from pynput.mouse import Listener, Controller, Button from pynput.keyboard import Key, Controller as KeyboardController import time import combine, settings from dataclasses import dataclass # Initialize mouse and keyboard controllers mouse = Controller() keyboard = KeyboardController() # Define global variables for monitoring keys shift_pressed = False ctrl_pressed = False alt_pressed = False # Define the subsections to act upon (Example: subsections 2, 4, and 6) selected_subsections = [2, 4, 6] @dataclass class SplitMode: combine=0 one=1 multi_ones=2 half=3 def perform_stack_action(clicked_subsection, x0, x1, y0, y1, clicked_point, time_delay=0.1, selected_subsections=selected_subsections, mode=SplitMode.multi_ones): """ Perform the Shift-drag, press 1, and click sequence for the clicked subsection. :param clicked_subsection: Index of the clicked subsection (0 to 6) :param x0: Leftmost x-coordinate of the rectangle :param x1: Rightmost x-coordinate of the rectangle :param y0: Topmost y-coordinate of the rectangle :param y1: Bottommost y-coordinate of the rectangle :param clicked_point: Tuple of (x, y) specifying the point to click after pressing '1' """ # Calculate the width of each subsection section_width = (x1 - x0) / 7 # Loop through all selected subsections for target_subsection in selected_subsections: # Skip if the clicked subsection is the same as the target subsection if target_subsection == clicked_subsection: continue # Calculate the center point of the target subsection target_center_x = x0 + target_subsection * section_width + section_width / 2 target_center_y = (y0 + y1) / 2 # Perform Shift-drag from the clicked point to the target subsection mouse.position = clicked_point # Move to the clicked point time.sleep(time_delay*3) keyboard.press(Key.shift) #, keyboard.pressed(Key.ctrl): mouse.press(Button.left) # Press and hold left mouse button time.sleep(time_delay) # Delay to simulate natural dragging mouse.position = (target_center_x, target_center_y) # Drag to the target subsection time.sleep(time_delay) # Delay for natural movement mouse.release(Button.left) # Release left mouse button keyboard.release(Key.shift) time.sleep(time_delay) if mode==SplitMode.half: mouse.position=(945,625) mouse.press(Button.left) mouse.release(Button.left) time.sleep(time_delay) else: # Edit the stack size to 1 mouse.position=(1050,560) mouse.press(Button.left) mouse.release(Button.left) time.sleep(time_delay) # Press the number '1' keyboard.press('1') keyboard.release('1') # Enter the 1 stack mouse.position=(840,710) mouse.press(Button.left) mouse.release(Button.left) time.sleep(time_delay) if mode==SplitMode.one or mode==SplitMode.half: break def on_click(x, y, button, pressed, is_injected, selection=selected_subsections): global shift_pressed, ctrl_pressed, alt_pressed x0, x1, y0, y1 = settings.BOX # Define rectangle bounds # Check if the click is within the rectangle if x0 <= x <= x1 and y0 <= y <= y1: # Determine which subsection the click occurred in section_width = (x1 - x0) / 7 clicked_subsection = int((x - x0) // section_width) # Define the clicked point for further actions clicked_point = (x, y) else: return if button == Button.left and pressed and shift_pressed and ctrl_pressed: # Perform the action perform_stack_action(clicked_subsection, x0, x1, y0, y1, clicked_point, selected_subsections=selection) elif button == Button.left and pressed and ctrl_pressed and alt_pressed: perform_stack_action(clicked_subsection, x0, x1, y0, y1, clicked_point, selected_subsections=selection, mode=SplitMode.half) elif button == Button.left and pressed and ctrl_pressed: perform_stack_action(clicked_subsection, x0, x1, y0, y1, clicked_point, selected_subsections=selection, mode=SplitMode.one) elif button == Button.left and pressed and alt_pressed: subsections=combine.split_section(x0, x1, y0, y1) combine.emulate_sequential_clicks(subsections) def on_press(key): global shift_pressed, ctrl_pressed, alt_pressed if key == Key.shift: shift_pressed = True elif key == Key.ctrl: ctrl_pressed = True elif key == Key.alt: alt_pressed = True def on_release(key): global shift_pressed, ctrl_pressed, alt_pressed if key == Key.shift: shift_pressed = False elif key == Key.ctrl: ctrl_pressed = False elif key == Key.alt: alt_pressed = False # Start the mouse and keyboard listeners if __name__ == "__main__": from pynput import keyboard as kb with Listener(on_click=on_click) as mouse_listener, kb.Listener(on_press=on_press, on_release=on_release) as keyboard_listener: mouse_listener.join() keyboard_listener.join()