232 lines
7.4 KiB
Python
232 lines
7.4 KiB
Python
import sys
|
||
import os
|
||
import keyboard
|
||
import pyautogui
|
||
import time
|
||
import ctypes
|
||
from python_imagesearch.imagesearch import imagesearch
|
||
from PySide6.QtWidgets import QApplication, QMainWindow
|
||
from PySide6.QtCore import QThread, Signal, QObject
|
||
from ui_main import Ui_MainWindow
|
||
|
||
MOUSEEVENTF_LEFTDOWN = 0x0002
|
||
MOUSEEVENTF_LEFTUP = 0x0004
|
||
MOUSEEVENTF_RIGHTDOWN = 0x0008
|
||
MOUSEEVENTF_RIGHTUP = 0x0010
|
||
|
||
def get_resource_path(relative_path):
|
||
""" Resimlere erişmek için doğru yolu oluşturur """
|
||
try:
|
||
base_path = sys._MEIPASS # PyInstaller için
|
||
except Exception:
|
||
base_path = os.path.abspath(".")
|
||
|
||
return os.path.join(base_path, relative_path)
|
||
|
||
|
||
class MacroWorker(QObject):
|
||
finished = Signal()
|
||
status_update = Signal(str)
|
||
|
||
def __init__(self, macro_manager):
|
||
super().__init__()
|
||
self.macro_manager = macro_manager
|
||
self.running = True
|
||
|
||
def run(self):
|
||
try:
|
||
while self.running:
|
||
self.macro_manager.run_macros()
|
||
time.sleep(0.05)
|
||
except Exception as e:
|
||
self.status_update.emit(f"Hata: {str(e)}")
|
||
finally:
|
||
self.finished.emit()
|
||
|
||
|
||
class MacroManager:
|
||
def __init__(self):
|
||
self.macros = {
|
||
'Atak': {'enabled': False, 'func': self.atak_macro},
|
||
'Kalkan Tak': {'enabled': False, 'func': self.kalkan_tak_macro},
|
||
'Restore Sil': {'enabled': False, 'func': self.restore_sil_macro},
|
||
'Kılıç Sil': {'enabled': False, 'func': self.kilic_sil_macro}
|
||
}
|
||
|
||
# Resim yollarını tanımla
|
||
self.image_paths = {
|
||
'kalkan': get_resource_path(os.path.join("img", "kalkan.png")),
|
||
'restore': get_resource_path(os.path.join("img", "restore.png"))
|
||
# Diğer resimler buraya eklenebilir
|
||
}
|
||
|
||
# MAKRO FONKSİYONLARI
|
||
@staticmethod
|
||
def atak_macro():
|
||
keyboard.press('r')
|
||
time.sleep(0.1)
|
||
keyboard.release('r')
|
||
time.sleep(0.5)
|
||
keyboard.press('r')
|
||
time.sleep(0.1)
|
||
keyboard.release('r')
|
||
time.sleep(0.5)
|
||
keyboard.press('2')
|
||
time.sleep(0.1)
|
||
keyboard.release('2')
|
||
|
||
def kalkan_tak_macro(self):
|
||
"""F tuşuna basıldığında bir kez çalışacak kalkan takma fonksiyonu"""
|
||
try:
|
||
# F tuşunun basılı olup olmadığını kontrol et
|
||
if not keyboard.is_pressed('f'):
|
||
return
|
||
|
||
# Resmi ara
|
||
pos = imagesearch(self.image_paths['kalkan'])
|
||
if pos[0] == -1:
|
||
return # Görsel bulunamazsa hiçbir şey yapma
|
||
|
||
# Görsel bulundu, işlemleri yap
|
||
pyautogui.moveTo(pos[0], pos[1] + 60, duration=0.1)
|
||
rclick(pos[0], pos[1] + 60)
|
||
|
||
# Tuş bırakılana kadar bekle (tekrar tetiklenmesini önle)
|
||
while keyboard.is_pressed('f'):
|
||
time.sleep(0.01)
|
||
|
||
except Exception as e:
|
||
print(f"Kalkan takma hatası: {e}")
|
||
|
||
def restore_sil_macro(self):
|
||
"""Ekranda restore görselini bulunca duble click (seri iki sol tıklama) yapar"""
|
||
try:
|
||
# Resim yolunu kontrol et
|
||
if 'restore' not in self.image_paths:
|
||
print("Restore resim yolu tanımlı değil!")
|
||
return
|
||
|
||
# Resmi ara
|
||
pos = imagesearch(self.image_paths['restore'])
|
||
if pos[0] == -1:
|
||
return # Görsel bulunamazsa hiçbir şey yapma
|
||
|
||
# Görsel bulundu, işlemleri yap
|
||
x, y = pos[0], pos[1]
|
||
|
||
# Duble click için fareyi konuma getir
|
||
ctypes.windll.user32.SetCursorPos(x + 5, y + 5)
|
||
|
||
# DUBLE CLICK (hızlı ardışık iki sol tıklama)
|
||
for _ in range(2):
|
||
ctypes.windll.user32.mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
|
||
ctypes.windll.user32.mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
|
||
time.sleep(0.03) # Çok kısa bekleme ile gerçekçi duble click
|
||
|
||
except Exception as e:
|
||
print(f"Restore silme hatası: {e}")
|
||
|
||
|
||
|
||
@staticmethod
|
||
def kilic_sil_macro():
|
||
keyboard.press('f4')
|
||
time.sleep(0.1)
|
||
keyboard.release('f4')
|
||
|
||
def run_macros(self):
|
||
for macro_name, macro_data in self.macros.items():
|
||
if macro_data['enabled']:
|
||
macro_data['func']()
|
||
|
||
|
||
class MainWindow(QMainWindow):
|
||
def __init__(self):
|
||
super().__init__()
|
||
self.ui = Ui_MainWindow()
|
||
self.ui.setupUi(self)
|
||
|
||
self.macro_manager = MacroManager()
|
||
self.worker = None
|
||
self.thread = None
|
||
|
||
# UI bağlantıları
|
||
self.ui.chk_atak.stateChanged.connect(
|
||
lambda: self.toggle_macro('Atak', self.ui.chk_atak))
|
||
self.ui.chk_kalkan.stateChanged.connect(
|
||
lambda: self.toggle_macro('Kalkan Tak', self.ui.chk_kalkan))
|
||
self.ui.chk_restore.stateChanged.connect(
|
||
lambda: self.toggle_macro('Restore Sil', self.ui.chk_restore))
|
||
self.ui.chk_kilic.stateChanged.connect(
|
||
lambda: self.toggle_macro('Kılıç Sil', self.ui.chk_kilic))
|
||
|
||
self.ui.btn_baslat.clicked.connect(self.toggle_macro_execution)
|
||
|
||
def toggle_macro(self, macro_name, checkbox):
|
||
self.macro_manager.macros[macro_name]['enabled'] = checkbox.isChecked()
|
||
|
||
def toggle_macro_execution(self):
|
||
if self.worker and self.worker.running:
|
||
self.stop_macros()
|
||
self.ui.btn_baslat.setText("Makro Başlat")
|
||
else:
|
||
self.start_macros()
|
||
self.ui.btn_baslat.setText("Makro Durdur")
|
||
|
||
def start_macros(self):
|
||
self.thread = QThread()
|
||
self.worker = MacroWorker(self.macro_manager)
|
||
self.worker.moveToThread(self.thread)
|
||
|
||
self.thread.started.connect(self.worker.run)
|
||
self.worker.finished.connect(self.thread.quit)
|
||
self.worker.finished.connect(self.worker.deleteLater)
|
||
self.thread.finished.connect(self.thread.deleteLater)
|
||
self.worker.status_update.connect(
|
||
lambda msg: self.ui.statusbar.showMessage(msg, 2000))
|
||
|
||
self.thread.start()
|
||
|
||
def stop_macros(self):
|
||
if self.worker:
|
||
self.worker.running = False
|
||
|
||
def closeEvent(self, event):
|
||
self.stop_macros()
|
||
event.accept()
|
||
|
||
def click(x, y):
|
||
ctypes.windll.user32.SetCursorPos(x, y)
|
||
ctypes.windll.user32.mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
|
||
time.sleep(0.3)
|
||
ctypes.windll.user32.mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
|
||
|
||
|
||
def rclick(x, y):
|
||
ctypes.windll.user32.SetCursorPos(x, y)
|
||
ctypes.windll.user32.mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
|
||
time.sleep(0.3)
|
||
ctypes.windll.user32.mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
|
||
|
||
|
||
def double_click(x, y):
|
||
"""Belirtilen konuma hızlı ardışık iki sol tıklama yapar"""
|
||
ctypes.windll.user32.SetCursorPos(x, y)
|
||
for _ in range(2):
|
||
ctypes.windll.user32.mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
|
||
ctypes.windll.user32.mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
|
||
time.sleep(0.03) # Gerçekçi duble click için
|
||
|
||
|
||
if __name__ == "__main__":
|
||
# Resim klasörünün varlığını kontrol et
|
||
img_dir = os.path.join(os.path.dirname(__file__), "img")
|
||
if not os.path.exists(img_dir):
|
||
os.makedirs(img_dir)
|
||
print(f"'img' klasörü oluşturuldu: {img_dir}")
|
||
|
||
app = QApplication(sys.argv)
|
||
window = MainWindow()
|
||
window.show()
|
||
sys.exit(app.exec())
|