forked from duma520/Mouse_Click_Simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouse_Click_Simulator.py
More file actions
2055 lines (1676 loc) · 82.4 KB
/
Mouse_Click_Simulator.py
File metadata and controls
2055 lines (1676 loc) · 82.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
__version__ = "2.4"
import sys
import os
import time
import threading
import json
import random
import platform
import psutil
import numpy as np
from datetime import datetime
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QLabel, QComboBox, QSpinBox, QPushButton, QGroupBox,
QLineEdit, QCheckBox, QTabWidget, QTextEdit, QFileDialog,
QSystemTrayIcon, QMenu, QAction, QMessageBox, QScrollArea,
QDoubleSpinBox, QTimeEdit, QColorDialog, QProgressBar, QInputDialog)
from PyQt5.QtCore import Qt, QSettings, QTimer, QTime, QSize, QByteArray, QPoint
from PyQt5.QtGui import QIcon, QColor, QPixmap, QImage,QPainter, QPen
import pyautogui
import keyboard
import cv2
from pynput.mouse import Controller as MouseController
from pynput.keyboard import GlobalHotKeys, Key, Listener as KeyboardListener
from screeninfo import get_monitors
from PIL import ImageGrab, Image
import requests
import socket
import pickle
import zlib
import base64
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import hashlib
import logging
from logging.handlers import RotatingFileHandler
# 设置日志
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
RotatingFileHandler('mouse_simulator.log', maxBytes=1024*1024, backupCount=5),
logging.StreamHandler()
]
)
class MouseClickSimulator(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("高级鼠标点击模拟器")
# 设置窗口图标
if os.path.exists("icon.ico"):
self.setWindowIcon(QIcon("icon.ico"))
elif os.path.exists("icon.png"): # 备用图标
self.setWindowIcon(QIcon("icon.png"))
# 设置最小尺寸
self.setMinimumSize(100, 100)
# 根据屏幕分辨率自动调整大小
screen = QApplication.primaryScreen()
screen_size = screen.size()
self.resize(int(screen_size.width()*0.4), int(screen_size.height()*0.7))
# 初始化设置
self.settings = QSettings("AdvancedMouseClickSimulator", "Config")
self.load_settings()
# 初始化变量
self.clicking = False
self.click_thread = None
self.click_count = 0
self.emergency_stop = False
self.mouse_positions = []
self.record_macro = False
self.macro_actions = []
self.color_trigger_active = False
self.image_trigger_active = False
self.timer_trigger_active = False
self.remote_control_active = False
self.remote_server = None
self.remote_thread = None
self.script_engine = None
self.tray_icon = None
# 初始化UI
self.init_ui()
self.setup_hotkeys()
self.setup_tray_icon()
# 启动监控定时器
self.monitor_timer = QTimer(self)
self.monitor_timer.timeout.connect(self.update_monitor)
self.monitor_timer.start(1000)
# 鼠标位置定时器
self.mouse_pos_timer = QTimer(self)
self.mouse_pos_timer.timeout.connect(self.update_mouse_position)
self.mouse_pos_timer.start(100)
# 初始化鼠标控制器
self.mouse_controller = MouseController()
# 初始化键盘监听器
self.keyboard_listener = KeyboardListener(on_press=self.on_key_press)
self.keyboard_listener.start()
# 检查开机自启动
self.check_autostart()
self.cpu_history = []
self.memory_history = []
self.max_history_points = 60 # 保留60个数据点
def init_ui(self):
# 创建主滚动区域
scroll = QScrollArea()
scroll.setWidgetResizable(True)
scroll.setFrameShape(QScrollArea.NoFrame)
main_widget = QWidget()
main_layout = QVBoxLayout(main_widget)
main_layout.setSpacing(10)
main_layout.setContentsMargins(10, 10, 10, 10)
# 创建标签页
self.tabs = QTabWidget()
self.tabs.setStyleSheet("""
QTabWidget::pane {
border: 1px solid #C0C0C0;
padding: 5px;
}
QTabBar::tab {
padding: 5px 10px;
min-width: 80px;
}
QTabBar::tab:selected {
background: #F0F0F0;
}
""")
# 基本设置标签页
self.basic_tab = self.create_scrollable_tab(self.init_basic_tab)
self.tabs.addTab(self.basic_tab, "基本设置")
# 高级设置标签页
self.advanced_tab = self.create_scrollable_tab(self.init_advanced_tab)
self.tabs.addTab(self.advanced_tab, "高级设置")
# 触发器标签页
self.trigger_tab = self.create_scrollable_tab(self.init_trigger_tab)
self.tabs.addTab(self.trigger_tab, "触发器")
# 脚本标签页
self.script_tab = self.create_scrollable_tab(self.init_script_tab)
self.tabs.addTab(self.script_tab, "脚本")
# 远程控制标签页
self.remote_tab = self.create_scrollable_tab(self.init_remote_tab)
self.tabs.addTab(self.remote_tab, "远程控制")
# 状态监控标签页
self.monitor_tab = self.create_scrollable_tab(self.init_monitor_tab)
self.tabs.addTab(self.monitor_tab, "状态监控")
# 添加到主布局
main_layout.addWidget(self.tabs)
# 控制按钮
control_layout = QHBoxLayout()
control_layout.setSpacing(10)
self.start_button = QPushButton("开始模拟")
self.start_button.setFixedHeight(35)
self.stop_button = QPushButton("停止模拟")
self.stop_button.setFixedHeight(35)
self.stop_button.setEnabled(False)
self.emergency_button = QPushButton("紧急停止 (ESC)")
self.emergency_button.setFixedHeight(35)
self.emergency_button.setStyleSheet("background-color: #FF4444; color: white;")
control_layout.addWidget(self.start_button)
control_layout.addWidget(self.stop_button)
control_layout.addWidget(self.emergency_button)
# 状态栏
self.status_bar = QLabel("状态: 未运行 | 点击次数: 0 | CPU: 0% | 内存: 0MB")
self.status_bar.setAlignment(Qt.AlignCenter)
self.status_bar.setStyleSheet("""
background-color: #F0F0F0;
padding: 8px;
border: 1px solid #C0C0C0;
border-radius: 3px;
""")
self.status_bar.setFixedHeight(35)
# 添加到主布局
main_layout.addLayout(control_layout)
main_layout.addWidget(self.status_bar)
# 设置滚动区域的内容
scroll.setWidget(main_widget)
self.setCentralWidget(scroll)
# 连接信号槽
self.start_button.clicked.connect(self.start_clicking)
self.stop_button.clicked.connect(self.stop_clicking)
self.emergency_button.clicked.connect(self.emergency_stop_func)
def create_scrollable_tab(self, content_init_func):
"""创建带有滚动条的可滚动标签页"""
scroll = QScrollArea()
scroll.setWidgetResizable(True)
scroll.setFrameShape(QScrollArea.NoFrame)
tab_content = QWidget()
layout = QVBoxLayout(tab_content)
layout.setSpacing(8)
layout.setContentsMargins(8, 8, 8, 8)
# 调用具体的内容初始化函数
content_init_func(layout)
# 添加拉伸项使内容顶部对齐
layout.addStretch()
scroll.setWidget(tab_content)
return scroll
def init_basic_tab(self, layout=None):
# 如果未传入layout参数,则创建新的布局(独立调用时)
if layout is None:
# 创建滚动区域
scroll = QScrollArea()
scroll.setWidgetResizable(True)
scroll.setFrameShape(QScrollArea.NoFrame)
# 主内容部件
tab_content = QWidget()
layout = QVBoxLayout(tab_content)
layout.setSpacing(10)
layout.setContentsMargins(10, 10, 10, 10)
# 递归调用自身传入layout参数
self.init_basic_tab(layout)
# 设置滚动区域内容
scroll.setWidget(tab_content)
self.basic_tab = scroll
return
# === 鼠标按键设置 ===
button_group = QGroupBox("鼠标按键设置")
button_layout = QVBoxLayout()
button_layout.setSpacing(5)
# 鼠标按键选择
button_row = QHBoxLayout()
button_row.addWidget(QLabel("选择鼠标按键:"))
self.button_combo = QComboBox()
self.button_combo.addItems(["左键", "中键", "右键"])
self.button_combo.setCurrentIndex(self.settings.value("basic/button_index", 0, type=int))
button_row.addWidget(self.button_combo)
button_row.addStretch()
button_layout.addLayout(button_row)
# 点击模式选择
mode_row = QHBoxLayout()
mode_row.addWidget(QLabel("点击模式:"))
self.click_mode_combo = QComboBox()
self.click_mode_combo.addItems(["单次点击", "双击", "三连击", "长按"])
self.click_mode_combo.setCurrentIndex(self.settings.value("basic/click_mode", 0, type=int))
self.click_mode_combo.currentIndexChanged.connect(self.update_click_mode)
mode_row.addWidget(self.click_mode_combo)
mode_row.addStretch()
button_layout.addLayout(mode_row)
# 长按时间设置
hold_row = QHBoxLayout()
hold_row.addWidget(QLabel("长按时间:"))
self.hold_time_spin = QSpinBox()
self.hold_time_spin.setRange(1, 10000)
self.hold_time_spin.setValue(self.settings.value("basic/hold_time", 100, type=int))
self.hold_time_spin.setSuffix("ms")
self.hold_time_spin.setEnabled(False)
hold_row.addWidget(self.hold_time_spin)
hold_row.addStretch()
button_layout.addLayout(hold_row)
button_group.setLayout(button_layout)
layout.addWidget(button_group)
# === 点击间隔设置 ===
interval_group = QGroupBox("点击间隔设置")
interval_layout = QVBoxLayout()
interval_layout.setSpacing(5)
# 固定间隔
fixed_row = QHBoxLayout()
fixed_row.addWidget(QLabel("点击间隔:"))
self.interval_spin = QSpinBox()
self.interval_spin.setRange(1, 1000000)
self.interval_spin.setValue(self.settings.value("basic/interval", 100, type=int))
self.interval_spin.setSuffix("ms")
fixed_row.addWidget(self.interval_spin)
fixed_row.addStretch()
interval_layout.addLayout(fixed_row)
# 随机间隔选项
self.random_interval_check = QCheckBox("随机间隔")
self.random_interval_check.setChecked(self.settings.value("basic/random_interval", False, type=bool))
self.random_interval_check.stateChanged.connect(self.update_interval_mode)
interval_layout.addWidget(self.random_interval_check)
# 随机间隔范围
min_max_row = QHBoxLayout()
min_max_row.addWidget(QLabel("最小间隔:"))
self.min_interval_spin = QSpinBox()
self.min_interval_spin.setRange(1, 1000000)
self.min_interval_spin.setValue(self.settings.value("basic/min_interval", 50, type=int))
self.min_interval_spin.setSuffix("ms")
self.min_interval_spin.setEnabled(self.random_interval_check.isChecked())
min_max_row.addWidget(self.min_interval_spin)
min_max_row.addSpacing(15)
min_max_row.addWidget(QLabel("最大间隔:"))
self.max_interval_spin = QSpinBox()
self.max_interval_spin.setRange(1, 1000000)
self.max_interval_spin.setValue(self.settings.value("basic/max_interval", 200, type=int))
self.max_interval_spin.setSuffix("ms")
self.max_interval_spin.setEnabled(self.random_interval_check.isChecked())
min_max_row.addWidget(self.max_interval_spin)
min_max_row.addStretch()
interval_layout.addLayout(min_max_row)
# 点击次数限制
limit_row = QHBoxLayout()
self.click_limit_check = QCheckBox("点击次数限制")
self.click_limit_check.setChecked(self.settings.value("basic/click_limit", False, type=bool))
limit_row.addWidget(self.click_limit_check)
self.click_limit_spin = QSpinBox()
self.click_limit_spin.setRange(1, 1000000)
self.click_limit_spin.setValue(self.settings.value("basic/click_limit_value", 100, type=int))
self.click_limit_spin.setEnabled(self.click_limit_check.isChecked())
limit_row.addWidget(self.click_limit_spin)
limit_row.addStretch()
interval_layout.addLayout(limit_row)
interval_group.setLayout(interval_layout)
layout.addWidget(interval_group)
# === 坐标设置 ===
position_group = QGroupBox("坐标设置")
position_layout = QVBoxLayout()
position_layout.setSpacing(5)
# 坐标模式选择
mode_row = QHBoxLayout()
mode_row.addWidget(QLabel("坐标模式:"))
self.position_mode_combo = QComboBox()
self.position_mode_combo.addItems(["当前鼠标位置", "固定坐标位置", "多坐标循环"])
self.position_mode_combo.setCurrentIndex(self.settings.value("basic/position_mode", 0, type=int))
self.position_mode_combo.currentIndexChanged.connect(self.update_position_mode)
mode_row.addWidget(self.position_mode_combo)
mode_row.addStretch()
position_layout.addLayout(mode_row)
# 固定坐标设置
fixed_pos_row = QHBoxLayout()
fixed_pos_row.addWidget(QLabel("X坐标:"))
self.x_spin = QSpinBox()
self.x_spin.setRange(0, 9999)
self.x_spin.setValue(self.settings.value("basic/x_position", 0, type=int))
self.x_spin.setEnabled(self.position_mode_combo.currentIndex() == 1)
fixed_pos_row.addWidget(self.x_spin)
fixed_pos_row.addSpacing(15)
fixed_pos_row.addWidget(QLabel("Y坐标:"))
self.y_spin = QSpinBox()
self.y_spin.setRange(0, 9999)
self.y_spin.setValue(self.settings.value("basic/y_position", 0, type=int))
self.y_spin.setEnabled(self.position_mode_combo.currentIndex() == 1)
fixed_pos_row.addWidget(self.y_spin)
fixed_pos_row.addStretch()
position_layout.addLayout(fixed_pos_row)
# 坐标列表
position_layout.addWidget(QLabel("坐标列表 (每行一个坐标,格式: x,y):"))
self.position_list = QTextEdit()
self.position_list.setPlainText(self.settings.value("basic/position_list", ""))
self.position_list.setEnabled(self.position_mode_combo.currentIndex() == 2)
position_layout.addWidget(self.position_list)
# 坐标列表操作按钮
btn_row = QHBoxLayout()
self.add_position_btn = QPushButton("添加当前位置")
self.add_position_btn.setEnabled(self.position_mode_combo.currentIndex() == 2)
self.add_position_btn.clicked.connect(self.add_current_position)
btn_row.addWidget(self.add_position_btn)
self.clear_positions_btn = QPushButton("清空列表")
self.clear_positions_btn.setEnabled(self.position_mode_combo.currentIndex() == 2)
self.clear_positions_btn.clicked.connect(self.clear_positions)
btn_row.addWidget(self.clear_positions_btn)
btn_row.addStretch()
position_layout.addLayout(btn_row)
position_group.setLayout(position_layout)
layout.addWidget(position_group)
# 添加拉伸项使内容顶部对齐
layout.addStretch()
def init_advanced_tab(self, layout=None):
# 如果未传入layout参数,则创建新的布局(独立调用时)
if layout is None:
# 创建滚动区域
scroll = QScrollArea()
scroll.setWidgetResizable(True)
scroll.setFrameShape(QScrollArea.NoFrame)
# 主内容部件
tab_content = QWidget()
layout = QVBoxLayout(tab_content)
layout.setSpacing(10)
layout.setContentsMargins(10, 10, 10, 10)
# 递归调用自身传入layout参数
self.init_advanced_tab(layout)
# 设置滚动区域内容
scroll.setWidget(tab_content)
self.advanced_tab = scroll
return
# === 游戏辅助设置 ===
game_group = QGroupBox("游戏辅助设置")
game_layout = QVBoxLayout()
game_layout.setSpacing(5)
self.combo_key_check = QCheckBox("组合键模拟")
self.combo_key_check.setChecked(self.settings.value("advanced/combo_key", False, type=bool))
self.combo_key_combo = QComboBox()
self.combo_key_combo.addItems(["左键+右键", "左键+中键", "右键+中键"])
self.combo_key_combo.setCurrentIndex(self.settings.value("advanced/combo_key_type", 0, type=int))
self.combo_key_combo.setEnabled(self.combo_key_check.isChecked())
self.recoil_check = QCheckBox("压枪模式")
self.recoil_check.setChecked(self.settings.value("advanced/recoil_mode", False, type=bool))
self.recoil_pattern_edit = QTextEdit()
self.recoil_pattern_edit.setPlainText(self.settings.value("advanced/recoil_pattern", "0,0\n0,1\n0,2\n0,1\n0,0"))
self.recoil_pattern_edit.setEnabled(self.recoil_check.isChecked())
self.anti_detect_check = QCheckBox("防检测机制")
self.anti_detect_check.setChecked(self.settings.value("advanced/anti_detect", False, type=bool))
self.random_offset_spin = QSpinBox()
self.random_offset_spin.setRange(0, 100)
self.random_offset_spin.setValue(self.settings.value("advanced/random_offset", 5, type=int))
self.random_offset_spin.setSuffix("px")
self.random_offset_spin.setEnabled(self.anti_detect_check.isChecked())
game_layout.addWidget(self.combo_key_check)
game_layout.addWidget(self.combo_key_combo)
game_layout.addWidget(self.recoil_check)
game_layout.addWidget(QLabel("压枪模式 (每行一个移动偏移量,格式:x,y):"))
game_layout.addWidget(self.recoil_pattern_edit)
game_layout.addWidget(self.anti_detect_check)
game_layout.addWidget(QLabel("随机偏移量:"))
game_layout.addWidget(self.random_offset_spin)
game_group.setLayout(game_layout)
# === 自动化测试设置 ===
test_group = QGroupBox("自动化测试设置")
test_layout = QVBoxLayout()
test_layout.setSpacing(5)
# 添加循环测试开关
self.test_loop_check = QCheckBox("启用循环测试次数限制")
self.test_loop_check.setChecked(self.settings.value("advanced/test_loop_enabled", True, type=bool))
self.test_loop_check.stateChanged.connect(self.update_test_loop_mode)
test_layout.addWidget(self.test_loop_check)
self.test_loop_spin = QSpinBox()
self.test_loop_spin.setRange(1, 100000)
self.test_loop_spin.setValue(self.settings.value("advanced/test_loop", 1, type=int))
self.test_loop_spin.setSuffix("次")
self.test_loop_spin.setEnabled(self.test_loop_check.isChecked())
self.verify_check = QCheckBox("结果验证")
self.verify_check.setChecked(self.settings.value("advanced/verify_result", False, type=bool))
self.verify_area_edit = QTextEdit()
self.verify_area_edit.setPlainText(self.settings.value("advanced/verify_area", "0,0,100,100"))
self.verify_area_edit.setEnabled(self.verify_check.isChecked())
self.report_check = QCheckBox("生成测试报告")
self.report_check.setChecked(self.settings.value("advanced/generate_report", True, type=bool))
test_layout.addWidget(QLabel("循环测试次数:"))
test_layout.addWidget(self.test_loop_spin)
test_layout.addWidget(self.verify_check)
test_layout.addWidget(QLabel("验证区域 (x1,y1,x2,y2):"))
test_layout.addWidget(self.verify_area_edit)
test_layout.addWidget(self.report_check)
test_group.setLayout(test_layout)
# === 系统设置 ===
system_group = QGroupBox("系统设置")
system_layout = QVBoxLayout()
system_layout.setSpacing(5)
self.autostart_check = QCheckBox("开机自动启动")
self.autostart_check.setChecked(self.settings.value("system/autostart", False, type=bool))
self.autostart_check.stateChanged.connect(
lambda: self.settings.setValue("system/autostart", self.autostart_check.isChecked())
)
system_layout.addWidget(self.autostart_check)
system_group.setLayout(system_layout)
# 添加到主布局
layout.addWidget(game_group)
layout.addWidget(test_group)
layout.addWidget(system_group)
# 添加拉伸项使内容顶部对齐
layout.addStretch()
def update_test_loop_mode(self, state):
"""更新测试循环模式状态"""
enabled = state == Qt.Checked
self.test_loop_spin.setEnabled(enabled)
def init_trigger_tab(self, layout=None):
# 如果未传入layout参数,则创建新的布局(独立调用时)
if layout is None:
# 创建滚动区域
scroll = QScrollArea()
scroll.setWidgetResizable(True)
scroll.setFrameShape(QScrollArea.NoFrame)
# 主内容部件
tab_content = QWidget()
layout = QVBoxLayout(tab_content)
layout.setSpacing(10)
layout.setContentsMargins(10, 10, 10, 10)
# 递归调用自身传入layout参数
self.init_trigger_tab(layout)
# 设置滚动区域内容
scroll.setWidget(tab_content)
self.trigger_tab = scroll
return
# === 颜色触发器 ===
color_group = QGroupBox("颜色触发器")
color_layout = QVBoxLayout()
color_layout.setSpacing(5)
self.color_trigger_check = QCheckBox("启用颜色触发")
self.color_trigger_check.setChecked(self.settings.value("trigger/color_trigger", False, type=bool))
self.color_trigger_check.stateChanged.connect(self.update_trigger_status)
pos_row = QHBoxLayout()
pos_row.addWidget(QLabel("检测位置 X:"))
self.color_x_spin = QSpinBox()
self.color_x_spin.setRange(0, 9999)
self.color_x_spin.setValue(self.settings.value("trigger/color_x", 0, type=int))
pos_row.addWidget(self.color_x_spin)
pos_row.addSpacing(15)
pos_row.addWidget(QLabel("Y:"))
self.color_y_spin = QSpinBox()
self.color_y_spin.setRange(0, 9999)
self.color_y_spin.setValue(self.settings.value("trigger/color_y", 0, type=int))
pos_row.addWidget(self.color_y_spin)
pos_row.addStretch()
self.target_color_btn = QPushButton("选择目标颜色")
self.target_color_btn.clicked.connect(self.select_target_color)
self.target_color = QColor(self.settings.value("trigger/target_color", "#FF0000"))
self.color_tolerance_spin = QSpinBox()
self.color_tolerance_spin.setRange(0, 255)
self.color_tolerance_spin.setValue(self.settings.value("trigger/color_tolerance", 10, type=int))
self.color_preview = QLabel()
self.color_preview.setFixedSize(50, 50)
self.update_color_preview()
color_layout.addWidget(self.color_trigger_check)
color_layout.addLayout(pos_row)
color_layout.addWidget(self.target_color_btn)
color_layout.addWidget(QLabel("颜色容差:"))
color_layout.addWidget(self.color_tolerance_spin)
color_layout.addWidget(QLabel("目标颜色:"))
color_layout.addWidget(self.color_preview)
color_group.setLayout(color_layout)
# === 图像触发器 ===
image_group = QGroupBox("图像触发器")
image_layout = QVBoxLayout()
image_layout.setSpacing(5)
self.image_trigger_check = QCheckBox("启用图像触发")
self.image_trigger_check.setChecked(self.settings.value("trigger/image_trigger", False, type=bool))
self.image_trigger_check.stateChanged.connect(self.update_trigger_status)
self.image_path_edit = QLineEdit(self.settings.value("trigger/image_path", ""))
self.browse_image_btn = QPushButton("浏览...")
self.browse_image_btn.clicked.connect(self.browse_image)
path_row = QHBoxLayout()
path_row.addWidget(self.image_path_edit)
path_row.addWidget(self.browse_image_btn)
self.capture_area_btn = QPushButton("捕捉屏幕区域")
self.capture_area_btn.clicked.connect(self.capture_screen_area)
self.confidence_spin = QDoubleSpinBox()
self.confidence_spin.setRange(0.1, 1.0)
self.confidence_spin.setValue(self.settings.value("trigger/confidence", 0.9, type=float))
self.confidence_spin.setSingleStep(0.05)
self.image_preview = QLabel()
self.image_preview.setFixedSize(100, 100)
self.update_image_preview()
image_layout.addWidget(self.image_trigger_check)
image_layout.addWidget(QLabel("目标图像路径:"))
image_layout.addLayout(path_row)
image_layout.addWidget(self.capture_area_btn)
image_layout.addWidget(QLabel("匹配置信度:"))
image_layout.addWidget(self.confidence_spin)
image_layout.addWidget(QLabel("目标图像预览:"))
image_layout.addWidget(self.image_preview)
image_group.setLayout(image_layout)
# === 定时触发器 ===
timer_group = QGroupBox("定时触发器")
timer_layout = QVBoxLayout()
timer_layout.setSpacing(5)
self.timer_trigger_check = QCheckBox("启用定时触发")
self.timer_trigger_check.setChecked(self.settings.value("trigger/timer_trigger", False, type=bool))
self.timer_trigger_check.stateChanged.connect(self.update_trigger_status)
time_row1 = QHBoxLayout()
time_row1.addWidget(QLabel("开始时间:"))
self.start_time_edit = QTimeEdit()
self.start_time_edit.setDisplayFormat("HH:mm:ss")
self.start_time_edit.setTime(QTime.fromString(self.settings.value("trigger/start_time", "00:00:00"), "HH:mm:ss"))
time_row1.addWidget(self.start_time_edit)
time_row1.addStretch()
time_row2 = QHBoxLayout()
time_row2.addWidget(QLabel("结束时间:"))
self.end_time_edit = QTimeEdit()
self.end_time_edit.setDisplayFormat("HH:mm:ss")
self.end_time_edit.setTime(QTime.fromString(self.settings.value("trigger/end_time", "23:59:59"), "HH:mm:ss"))
time_row2.addWidget(self.end_time_edit)
time_row2.addStretch()
timer_layout.addWidget(self.timer_trigger_check)
timer_layout.addLayout(time_row1)
timer_layout.addLayout(time_row2)
timer_group.setLayout(timer_layout)
# 添加到主布局
layout.addWidget(color_group)
layout.addWidget(image_group)
layout.addWidget(timer_group)
# 添加拉伸项使内容顶部对齐
layout.addStretch()
def init_script_tab(self, layout=None):
"""初始化脚本标签页内容"""
# 如果未传入layout参数,则创建新的布局(独立调用时)
if layout is None:
# 创建滚动区域
scroll = QScrollArea()
scroll.setWidgetResizable(True)
scroll.setFrameShape(QScrollArea.NoFrame)
# 主内容部件
tab_content = QWidget()
layout = QVBoxLayout(tab_content)
layout.setSpacing(10)
layout.setContentsMargins(10, 10, 10, 10)
# 递归调用自身传入layout参数
self.init_script_tab(layout)
# 设置滚动区域内容
scroll.setWidget(tab_content)
self.script_tab = scroll
return
# === 宏录制 ===
macro_group = QGroupBox("宏录制")
macro_layout = QVBoxLayout()
macro_layout.setSpacing(5)
self.record_macro_btn = QPushButton("开始录制宏")
self.record_macro_btn.clicked.connect(self.toggle_record_macro)
self.stop_record_btn = QPushButton("停止录制")
self.stop_record_btn.setEnabled(False)
self.stop_record_btn.clicked.connect(self.stop_record_macro)
self.play_macro_btn = QPushButton("播放宏")
self.play_macro_btn.clicked.connect(self.play_macro)
self.save_macro_btn = QPushButton("保存宏")
self.save_macro_btn.clicked.connect(self.save_macro)
self.load_macro_btn = QPushButton("加载宏")
self.load_macro_btn.clicked.connect(self.load_macro)
self.macro_info = QTextEdit()
self.macro_info.setReadOnly(True)
# 按钮水平布局
button_row1 = QHBoxLayout()
button_row1.addWidget(self.record_macro_btn)
button_row1.addWidget(self.stop_record_btn)
button_row2 = QHBoxLayout()
button_row2.addWidget(self.play_macro_btn)
button_row2.addWidget(self.save_macro_btn)
button_row2.addWidget(self.load_macro_btn)
macro_layout.addLayout(button_row1)
macro_layout.addLayout(button_row2)
macro_layout.addWidget(QLabel("宏信息:"))
macro_layout.addWidget(self.macro_info)
macro_group.setLayout(macro_layout)
# === 脚本编辑 ===
script_group = QGroupBox("脚本编辑")
script_layout = QVBoxLayout()
script_layout.setSpacing(5)
self.script_edit = QTextEdit()
self.script_edit.setPlainText(self.settings.value("script/code",
"# 在这里编写自定义脚本\n"
"# 可以使用以下变量:\n"
"# - mouse: 鼠标控制器\n"
"# - keyboard: 键盘控制器\n"
"# - pyautogui: pyautogui模块\n"
"# - time: 时间模块\n\n"
"# 示例: 移动鼠标并点击\n"
"# mouse.move(100, 100)\n"
"# mouse.click('left')\n"))
self.run_script_btn = QPushButton("运行脚本")
self.run_script_btn.clicked.connect(self.run_script)
script_layout.addWidget(self.script_edit)
script_layout.addWidget(self.run_script_btn)
script_group.setLayout(script_layout)
# 添加到主布局
layout.addWidget(macro_group)
layout.addWidget(script_group)
# 添加拉伸项使内容顶部对齐
layout.addStretch()
def init_remote_tab(self, layout=None):
# 如果未传入layout参数,则创建新的布局(独立调用时)
if layout is None:
# 创建滚动区域
scroll = QScrollArea()
scroll.setWidgetResizable(True)
scroll.setFrameShape(QScrollArea.NoFrame)
# 主内容部件
tab_content = QWidget()
layout = QVBoxLayout(tab_content)
layout.setSpacing(10)
layout.setContentsMargins(10, 10, 10, 10)
# 递归调用自身传入layout参数
self.init_remote_tab(layout)
# 设置滚动区域内容
scroll.setWidget(tab_content)
self.remote_tab = scroll
return
# === 远程控制设置 ===
remote_group = QGroupBox("远程控制设置")
remote_layout = QVBoxLayout()
remote_layout.setSpacing(5)
self.remote_enable_check = QCheckBox("启用远程控制")
self.remote_enable_check.setChecked(self.settings.value("remote/enabled", False, type=bool))
self.remote_enable_check.stateChanged.connect(self.toggle_remote_control)
self.remote_port_spin = QSpinBox()
self.remote_port_spin.setRange(1024, 65535)
self.remote_port_spin.setValue(self.settings.value("remote/port", 12345, type=int))
self.remote_password_edit = QLineEdit()
self.remote_password_edit.setPlaceholderText("设置远程控制密码")
self.remote_password_edit.setText(self.settings.value("remote/password", ""))
self.remote_password_edit.setEchoMode(QLineEdit.Password)
self.remote_status_label = QLabel("状态: 未运行")
remote_layout.addWidget(self.remote_enable_check)
remote_layout.addWidget(QLabel("端口号:"))
remote_layout.addWidget(self.remote_port_spin)
remote_layout.addWidget(QLabel("密码:"))
remote_layout.addWidget(self.remote_password_edit)
remote_layout.addWidget(self.remote_status_label)
remote_group.setLayout(remote_layout)
# === 远程脚本库 ===
script_lib_group = QGroupBox("远程脚本库")
script_lib_layout = QVBoxLayout()
script_lib_layout.setSpacing(5)
self.script_list = QComboBox()
self.script_list.addItems(["加载脚本...", "基本点击脚本", "游戏辅助脚本", "自动化测试脚本"])
self.download_script_btn = QPushButton("下载脚本")
self.download_script_btn.clicked.connect(self.download_script)
self.upload_script_btn = QPushButton("上传脚本")
self.upload_script_btn.clicked.connect(self.upload_script)
script_lib_layout.addWidget(self.script_list)
script_lib_layout.addWidget(self.download_script_btn)
script_lib_layout.addWidget(self.upload_script_btn)
script_lib_group.setLayout(script_lib_layout)
# === 连接测试区域 ===
test_group = QGroupBox("连接测试")
test_layout = QVBoxLayout()
test_layout.setSpacing(5)
self.test_connection_btn = QPushButton("测试连接")
self.test_connection_btn.clicked.connect(self.test_remote_connection)
self.connection_status = QLabel("未测试")
test_layout.addWidget(self.test_connection_btn)
test_layout.addWidget(self.connection_status)
test_group.setLayout(test_layout)
# 添加到主布局
layout.addWidget(remote_group)
layout.addWidget(script_lib_group)
layout.addWidget(test_group)
# 添加拉伸项使内容顶部对齐
layout.addStretch()
# 添加样式
remote_group.setStyleSheet("""
QGroupBox {
margin-top: 10px;
border: 1px solid #C0C0C0;
border-radius: 3px;
}
QGroupBox::title {
subcontrol-origin: margin;
left: 10px;
padding: 0 3px;
}
QLineEdit {
padding: 3px;
}
""")
def test_remote_connection(self):
"""测试远程连接"""
if not self.remote_control_active:
self.connection_status.setText("错误: 远程控制未启用")
self.connection_status.setStyleSheet("color: red;")
return
try:
# 创建测试套接字
test_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
test_socket.settimeout(2) # 2秒超时
test_socket.connect(('127.0.0.1', self.remote_port_spin.value()))
test_socket.close()
self.connection_status.setText("连接成功")
self.connection_status.setStyleSheet("color: green;")
except Exception as e:
self.connection_status.setText(f"连接失败: {str(e)}")
self.connection_status.setStyleSheet("color: red;")
def init_monitor_tab(self, layout=None):
# 如果未传入layout参数,则创建新的布局(独立调用时)
if layout is None:
# 创建滚动区域
scroll = QScrollArea()
scroll.setWidgetResizable(True)
scroll.setFrameShape(QScrollArea.NoFrame)
# 主内容部件
tab_content = QWidget()
layout = QVBoxLayout(tab_content)
layout.setSpacing(10)
layout.setContentsMargins(10, 10, 10, 10)
# 递归调用自身传入layout参数
self.init_monitor_tab(layout)
# 设置滚动区域内容
scroll.setWidget(tab_content)
self.monitor_tab = scroll
return
# === 状态监控 ===
monitor_group = QGroupBox("状态监控")
monitor_layout = QVBoxLayout()
monitor_layout.setSpacing(5)
self.click_count_label = QLabel("点击次数: 0")
self.mouse_position_label = QLabel("鼠标位置: (0, 0)")
self.cpu_usage_label = QLabel("CPU使用率: 0%")
self.memory_usage_label = QLabel("内存使用: 0MB")
self.cpu_usage_bar = QProgressBar()
self.cpu_usage_bar.setRange(0, 100)
self.cpu_usage_bar.setStyleSheet("""
QProgressBar {
text-align: center;
border: 1px solid #C0C0C0;
border-radius: 3px;
}
QProgressBar::chunk {
background-color: #4CAF50;
}
""")
self.memory_usage_bar = QProgressBar()
self.memory_usage_bar.setRange(0, 100)
self.memory_usage_bar.setStyleSheet("""
QProgressBar {
text-align: center;
border: 1px solid #C0C0C0;
border-radius: 3px;
}
QProgressBar::chunk {
background-color: #2196F3;
}
""")
monitor_layout.addWidget(self.click_count_label)
monitor_layout.addWidget(self.mouse_position_label)
monitor_layout.addWidget(self.cpu_usage_label)
monitor_layout.addWidget(self.cpu_usage_bar)
monitor_layout.addWidget(self.memory_usage_label)
monitor_layout.addWidget(self.memory_usage_bar)
# 添加性能图表
self.cpu_chart = QLabel("CPU使用率图表")
self.cpu_chart.setFixedHeight(150)
self.cpu_chart.setStyleSheet("""
background-color: white;
border: 1px solid #C0C0C0;
border-radius: 3px;
""")
self.memory_chart = QLabel("内存使用率图表")
self.memory_chart.setFixedHeight(150)
self.memory_chart.setStyleSheet("""
background-color: white;
border: 1px solid #C0C0C0;