196 lines
6.6 KiB
Python
196 lines
6.6 KiB
Python
from PySide6.QtWidgets import QApplication, QMainWindow
|
||
from PySide6.QtCore import QThread, Signal, QObject
|
||
import keyboard
|
||
import sys
|
||
import time
|
||
import os
|
||
import ctypes
|
||
import pyautogui
|
||
from python_imagesearch.imagesearch import imagesearch
|
||
import random
|
||
from ui_main import Ui_MainWindow
|
||
|
||
|
||
MOUSEEVENTF_LEFTDOWN = 0x0002
|
||
MOUSEEVENTF_LEFTUP = 0x0004
|
||
MOUSEEVENTF_RIGHTDOWN = 0x0008
|
||
MOUSEEVENTF_RIGHTUP = 0x0010
|
||
|
||
def get_resource_path(relative_path):
|
||
if hasattr(sys, '_MEIPASS'):
|
||
return os.path.join(sys._MEIPASS, relative_path)
|
||
return os.path.join(os.path.abspath("."), relative_path)
|
||
|
||
class MacroWorker(QObject):
|
||
finished = Signal()
|
||
status_update = Signal(str)
|
||
|
||
def __init__(self, macros):
|
||
super().__init__()
|
||
self.macros = macros
|
||
self.running = True
|
||
# kalkanimg = self.base_path = get_resource_path(os.path.join("img", "kalkan.png"))
|
||
# restimg = self.base_path = get_resource_path(os.path.join("img", "restore.png"))
|
||
|
||
def run(self):
|
||
try:
|
||
while self.running:
|
||
for macro_name, macro_data in self.macros.items():
|
||
if macro_data['enabled']:
|
||
self.execute_macro(macro_name)
|
||
time.sleep(0.1) # Makrolar arası bekleme
|
||
except Exception as e:
|
||
self.status_update.emit(f"Hata: {str(e)}")
|
||
finally:
|
||
self.finished.emit()
|
||
|
||
def execute_macro(self, macro_name):
|
||
actions = self.macros[macro_name]['actions']
|
||
self.status_update.emit(f"{macro_name} çalıştırılıyor...")
|
||
|
||
for action in actions:
|
||
if not self.running:
|
||
break
|
||
|
||
if action['type'] == 'press':
|
||
keyboard.press(action['key'])
|
||
elif action['type'] == 'release':
|
||
keyboard.release(action['key'])
|
||
elif action['type'] == 'delay':
|
||
time.sleep(action['duration'])
|
||
|
||
def stop(self):
|
||
self.running = False
|
||
|
||
|
||
class MainWindow(QMainWindow):
|
||
def __init__(self):
|
||
super().__init__()
|
||
self.ui = Ui_MainWindow()
|
||
self.ui.setupUi(self)
|
||
|
||
# Makro tanımları
|
||
self.macros = {
|
||
'Atak': {
|
||
'enabled': False,
|
||
'actions': [
|
||
{'type': 'press', 'key': 'r'},
|
||
{'type': 'delay', 'duration': 0.1},
|
||
{'type': 'release', 'key': 'r'},
|
||
{'type': 'press', 'key': 'r'},
|
||
{'type': 'delay', 'duration': 0.1},
|
||
{'type': 'release', 'key': 'r'},
|
||
{'type': 'press', 'key': '2'},
|
||
{'type': 'delay', 'duration': 0.1},
|
||
{'type': 'release', 'key': '2'}
|
||
]
|
||
},
|
||
'Kalkan Tak': {
|
||
'enabled': False,
|
||
'actions': [
|
||
{
|
||
'type': 'conditional_image_search',
|
||
'image': 'kalkan.png',
|
||
'region': (150, 411, 130, 86),
|
||
'precision': 0.8,
|
||
'if_found': [
|
||
{'type': 'mouse_move', 'x': 'found_x', 'y': 'found_y+60'},
|
||
{'type': 'mouse_rclick'}],
|
||
'if_not_found': []
|
||
}
|
||
]
|
||
},
|
||
'Restore Sil': {
|
||
'enabled': False,
|
||
'actions': [
|
||
{
|
||
'type': 'conditional_image_search',
|
||
'image': 'restore.png',
|
||
'region': (719, 456, 489, 118),
|
||
'precision': 0.5,
|
||
'if_found': [
|
||
{'type': 'mouse_move', 'x': 'found_x', 'y': 'found_y'},
|
||
{'type': 'mouse_doubleclick'}],
|
||
'if_not_found': []
|
||
}
|
||
]
|
||
},
|
||
'Kılıç Sil': {
|
||
'enabled': False,
|
||
'actions': [
|
||
{'type': 'press', 'key': 'f4'},
|
||
{'type': 'delay', 'duration': 0.1},
|
||
{'type': 'release', 'key': 'f4'}
|
||
]
|
||
}
|
||
}
|
||
|
||
# Thread ve worker için değişkenler
|
||
self.thread = None
|
||
self.worker = None
|
||
|
||
# UI bağlantıları
|
||
self.ui.btn_baslat.clicked.connect(self.toggle_macro)
|
||
self.ui.chk_atak.stateChanged.connect(lambda: self.update_macro_state('Atak', self.ui.chk_atak))
|
||
self.ui.chk_kalkan.stateChanged.connect(lambda: self.update_macro_state('Kalkan Tak', self.ui.chk_kalkan))
|
||
self.ui.chk_restore.stateChanged.connect(lambda: self.update_macro_state('Restore Sil', self.ui.chk_restore))
|
||
self.ui.chk_kilic.stateChanged.connect(lambda: self.update_macro_state('Kılıç Sil', self.ui.chk_kilic))
|
||
|
||
# Başlangıç durumu
|
||
self.macro_running = False
|
||
|
||
def update_macro_state(self, macro_name, checkbox):
|
||
self.macros[macro_name]['enabled'] = checkbox.isChecked()
|
||
|
||
def toggle_macro(self):
|
||
if self.macro_running:
|
||
self.stop_macro()
|
||
self.ui.btn_baslat.setText("Makro Başlat")
|
||
else:
|
||
self.start_macro()
|
||
self.ui.btn_baslat.setText("Makro Durdur")
|
||
|
||
def start_macro(self):
|
||
if not any(macro['enabled'] for macro in self.macros.values()):
|
||
self.ui.statusbar.showMessage("En az bir makro seçmelisiniz!", 3000)
|
||
return
|
||
|
||
self.macro_running = True
|
||
|
||
# Thread ve worker oluştur
|
||
self.thread = QThread()
|
||
self.worker = MacroWorker(self.macros)
|
||
self.worker.moveToThread(self.thread)
|
||
|
||
# Signal-slot bağlantıları
|
||
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(self.update_status)
|
||
|
||
# Thread'i başlat
|
||
self.thread.start()
|
||
|
||
self.ui.statusbar.showMessage("Makro çalışıyor...")
|
||
|
||
def stop_macro(self):
|
||
if self.worker:
|
||
self.worker.stop()
|
||
self.macro_running = False
|
||
self.ui.statusbar.showMessage("Makro durduruldu", 3000)
|
||
|
||
def update_status(self, message):
|
||
self.ui.statusbar.showMessage(message, 1000)
|
||
|
||
def closeEvent(self, event):
|
||
if self.macro_running:
|
||
self.stop_macro()
|
||
event.accept()
|
||
|
||
|
||
if __name__ == "__main__":
|
||
app = QApplication(sys.argv)
|
||
window = MainWindow()
|
||
window.show()
|
||
sys.exit(app.exec()) |