Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import time
- import threading
- import pyautogui
- from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QGridLayout, QWidget, QPushButton, QDoubleSpinBox
- import keyboard
- from PyQt5.QtGui import QCursor, QPainter, QPen
- from PyQt5.QtCore import Qt, QRect
- class MainWindow(QMainWindow):
- def __init__(self):
- super().__init__()
- self.is_adding_point = False
- self.setWindowTitle("Autoclicker (zatrzymany)")
- central_widget = QWidget()
- grid_layout = QGridLayout()
- label1 = QLabel("Punkty kliknięcia:")
- self.points_edit = QLabel("")
- self.points_edit.setWordWrap(True)
- label2 = QLabel("Czas między kliknięciami (s):")
- self.interval_spinbox = QDoubleSpinBox()
- self.interval_spinbox.setRange(0.01, 60.0)
- self.interval_spinbox.setSingleStep(0.01)
- self.interval_spinbox.setValue(0.5)
- label3 = QLabel("Czas między cyklami (s):")
- self.cycle_interval_spinbox = QDoubleSpinBox()
- self.cycle_interval_spinbox.setRange(0.01, 60.0)
- self.cycle_interval_spinbox.setSingleStep(0.01)
- self.cycle_interval_spinbox.setValue(2.0)
- start_button = QPushButton("Start")
- start_button.clicked.connect(self.start_clicker)
- stop_button = QPushButton("Stop")
- stop_button.clicked.connect(self.stop_clicker)
- add_button = QPushButton("Dodaj punkt")
- add_button.clicked.connect(self.add_point)
- clear_button = QPushButton("Wyczysc punkty")
- clear_button.clicked.connect(self.clear_point)
- grid_layout.addWidget(label1, 0, 0)
- grid_layout.addWidget(self.points_edit, 0, 1)
- grid_layout.addWidget(label2, 1, 0)
- grid_layout.addWidget(self.interval_spinbox, 1, 1)
- grid_layout.addWidget(label3, 2, 0)
- grid_layout.addWidget(self.cycle_interval_spinbox, 2, 1)
- grid_layout.addWidget(start_button, 3, 0)
- grid_layout.addWidget(stop_button, 3, 1)
- grid_layout.addWidget(add_button, 4, 0)
- grid_layout.addWidget(clear_button, 4, 1)
- central_widget.setLayout(grid_layout)
- self.setCentralWidget(central_widget)
- self.mousePressEvent = self.handle_mouse_press_event
- self.points = []
- self.click_thread = None
- self.is_clicking = False
- def handle_keyboard_press(key):
- if key.name == "f10":
- self.stop_clicker()
- keyboard.on_press(handle_keyboard_press)
- def start_clicker(self):
- self.is_clicking = True
- self.click_thread = threading.Thread(target=self.click_loop)
- self.click_thread.start()
- self.setWindowTitle("Autoclicker (wystartowany)")
- def stop_clicker(self):
- self.is_clicking = False
- self.click_thread.join()
- self.setWindowTitle("Autoclicker (zatrzymany)")
- def click_loop(self):
- while self.is_clicking:
- if not self.is_clicking: break;
- interval = self.interval_spinbox.value()
- for point in self.points:
- if not self.is_clicking: break;
- pyautogui.click(x=point[0], y=point[1])
- time.sleep(interval)
- cycle_interval = self.cycle_interval_spinbox.value()
- time.sleep(cycle_interval)
- def mousePressEvent(self, event):
- x, y = pyautogui.position()
- self.points.append((x, y))
- self.update_points()
- def handle_mouse_press_event(self, event):
- if(self.is_adding_point):
- self.is_adding_point = False
- x, y = event.pos().x(), event.pos().y()
- self.points.append((x, y))
- self.update_points()
- def clear_point(self):
- self.points.clear();
- self.points_edit.setText("")
- if self.is_clicking:
- self.stop_clicker();
- def add_point(self):
- self.is_adding_point = True
- if self.is_clicking:
- self.stop_clicker();
- def update_points(self):
- points_text = ""
- for point in self.points:
- points_text += f"{point[0]},{point[1]};"
- self.points_edit.setText(points_text)
- if __name__ == "__main__":
- app = QApplication(sys.argv)
- window = MainWindow()
- window.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement