Advertisement
programusy

Untitled

Apr 20th, 2023
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.33 KB | None | 0 0
  1. import sys
  2. import time
  3. import threading
  4. import pyautogui
  5. from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QGridLayout, QWidget, QPushButton, QDoubleSpinBox
  6. import keyboard
  7. from PyQt5.QtGui import QCursor, QPainter, QPen
  8. from PyQt5.QtCore import Qt, QRect
  9.  
  10. class MainWindow(QMainWindow):
  11.     def __init__(self):
  12.         super().__init__()
  13.  
  14.         self.is_adding_point = False
  15.  
  16.         self.setWindowTitle("Autoclicker (zatrzymany)")
  17.  
  18.         central_widget = QWidget()
  19.         grid_layout = QGridLayout()
  20.  
  21.         label1 = QLabel("Punkty kliknięcia:")
  22.         self.points_edit = QLabel("")
  23.         self.points_edit.setWordWrap(True)
  24.  
  25.         label2 = QLabel("Czas między kliknięciami (s):")
  26.         self.interval_spinbox = QDoubleSpinBox()
  27.         self.interval_spinbox.setRange(0.01, 60.0)
  28.         self.interval_spinbox.setSingleStep(0.01)
  29.         self.interval_spinbox.setValue(0.5)
  30.  
  31.         label3 = QLabel("Czas między cyklami (s):")
  32.         self.cycle_interval_spinbox = QDoubleSpinBox()
  33.         self.cycle_interval_spinbox.setRange(0.01, 60.0)
  34.         self.cycle_interval_spinbox.setSingleStep(0.01)
  35.         self.cycle_interval_spinbox.setValue(2.0)
  36.  
  37.         start_button = QPushButton("Start")
  38.         start_button.clicked.connect(self.start_clicker)
  39.  
  40.         stop_button = QPushButton("Stop")
  41.         stop_button.clicked.connect(self.stop_clicker)
  42.  
  43.         add_button = QPushButton("Dodaj punkt")
  44.         add_button.clicked.connect(self.add_point)
  45.  
  46.         clear_button = QPushButton("Wyczysc punkty")
  47.         clear_button.clicked.connect(self.clear_point)
  48.  
  49.         grid_layout.addWidget(label1, 0, 0)
  50.         grid_layout.addWidget(self.points_edit, 0, 1)
  51.  
  52.         grid_layout.addWidget(label2, 1, 0)
  53.         grid_layout.addWidget(self.interval_spinbox, 1, 1)
  54.  
  55.         grid_layout.addWidget(label3, 2, 0)
  56.         grid_layout.addWidget(self.cycle_interval_spinbox, 2, 1)
  57.  
  58.         grid_layout.addWidget(start_button, 3, 0)
  59.         grid_layout.addWidget(stop_button, 3, 1)
  60.         grid_layout.addWidget(add_button, 4, 0)
  61.         grid_layout.addWidget(clear_button, 4, 1)
  62.  
  63.         central_widget.setLayout(grid_layout)
  64.         self.setCentralWidget(central_widget)
  65.         self.mousePressEvent = self.handle_mouse_press_event
  66.  
  67.         self.points = []
  68.         self.click_thread = None
  69.         self.is_clicking = False
  70.  
  71.         def handle_keyboard_press(key):
  72.             if key.name == "f10":
  73.                 self.stop_clicker()
  74.  
  75.         keyboard.on_press(handle_keyboard_press)
  76.     def start_clicker(self):
  77.         self.is_clicking = True
  78.         self.click_thread = threading.Thread(target=self.click_loop)
  79.         self.click_thread.start()
  80.         self.setWindowTitle("Autoclicker (wystartowany)")
  81.  
  82.     def stop_clicker(self):
  83.         self.is_clicking = False
  84.         self.click_thread.join()
  85.         self.setWindowTitle("Autoclicker (zatrzymany)")
  86.  
  87.     def click_loop(self):
  88.         while self.is_clicking:
  89.             if not self.is_clicking: break;
  90.             interval = self.interval_spinbox.value()
  91.  
  92.             for point in self.points:
  93.                 if not self.is_clicking: break;
  94.                 pyautogui.click(x=point[0], y=point[1])
  95.                 time.sleep(interval)
  96.  
  97.             cycle_interval = self.cycle_interval_spinbox.value()
  98.             time.sleep(cycle_interval)
  99.  
  100.     def mousePressEvent(self, event):
  101.         x, y = pyautogui.position()
  102.         self.points.append((x, y))
  103.         self.update_points()
  104.  
  105.     def handle_mouse_press_event(self, event):
  106.         if(self.is_adding_point):
  107.             self.is_adding_point = False
  108.             x, y = event.pos().x(), event.pos().y()
  109.             self.points.append((x, y))
  110.             self.update_points()
  111.  
  112.     def clear_point(self):
  113.         self.points.clear();
  114.         self.points_edit.setText("")
  115.         if self.is_clicking:
  116.             self.stop_clicker();
  117.     def add_point(self):
  118.         self.is_adding_point = True
  119.         if self.is_clicking:
  120.             self.stop_clicker();
  121.  
  122.     def update_points(self):
  123.         points_text = ""
  124.         for point in self.points:
  125.             points_text += f"{point[0]},{point[1]};"
  126.         self.points_edit.setText(points_text)
  127.  
  128. if __name__ == "__main__":
  129.     app = QApplication(sys.argv)
  130.     window = MainWindow()
  131.     window.show()
  132.     sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement