-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
227 lines (183 loc) · 6.05 KB
/
script.py
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
from PyQt5.QtWidgets import QApplication
from pynput import keyboard, mouse
from PyQt5.QtGui import QIcon
from threading import Thread
from PyQt5.uic import loadUi
from PyQt5.QtCore import Qt
from os import _exit, path
from random import randint
import win32api, win32con
from time import sleep
import pyautogui
import json
def main() :
"""
choose mouse or keyboard
probability keyboard=0.9, mouse=0.1
"""
global mainThread
time = win.timeInput.text()
if time == "" :
time = 86400 # equivalent to 1 day
elif not time.isdigit() :
win.error.setText("This number isn't valid !")
return
else :
time = int(time)
mainThread = Thread(target=loopThread, args=[time], daemon=True)
mainThread.start()
def stopMain() :
global endProgramme
endProgramme = True
win.timeLeft.setText("STOPED")
return
def loopThread(time) :
global endProgramme
mouseLeftAlowed = win.mouseLeft.isChecked()
mouseRightAlowed = win.mouseRight.isChecked()
mouseMoveAlowed = win.mouseMovement.isChecked()
sleep(1)
while not endProgramme and time > 0 :
randKeyboard()
randMouse(mouseLeftAlowed, mouseRightAlowed, mouseMoveAlowed)
sleepTime = randint(0, 10) / 100
sleep(sleepTime)
if time :
time -= sleepTime
win.timeLeft.setText("Time Left : "+str(int(time))+"s")
if win.autoExit.isChecked():
_exit(0)
win.timeLeft.setText("STOPED")
endProgramme = False
def randMouse(mouseLeftAlowed, mouseRightAlowed, mouseMoveAlowed) :
r = randint(0, 10)
if mouseLeftAlowed and r in [0, 1, 2] :
print("left click !")
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
sleep(.01)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
# pyautogui.leftClick(duration=0.2, interval=0.1)
if mouseRightAlowed and r == 9:
print("right click !")
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0)
sleep(.01)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 0, 0)
# pyautogui.leftClick(duration=0.2, interval=0.1)
if mouseMoveAlowed and r in [1, 2, 3, 4, 5, 6, 7, 8] :
screen = App.primaryScreen()
size = screen.size()
w, h = size.width(), size.height()
win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, randint(20, w // 2), randint(20, h // 2), 0, 0)
def randKeyboard():
if len(alowedMoves) == 0 :
return
r = randint(0, len(alowedMoves) - 1)
pressKey(alowedMoves[r], randint(0, 500) / 100)
def pressKey(key, duration):
pyautogui.keyDown(key)
sleep(duration)
pyautogui.keyUp(key)
return
def on_press(key) :
global endProgramme
if key == keyboard.Key.esc:
endProgramme = True
elif key == keyboard.Key.f1:
endProgramme = False
main()
def initWin(winTitle):
"""
Initializes the win object with the specified win title.
Parameters:
winTitle (str): The title to set for the win window.
Returns:
None
"""
win.setWindowTitle(winTitle)
win.setWindowIcon(QIcon('./ui/icon.png'))
win.setWindowFlags(Qt.FramelessWindowHint | Qt.Window | Qt.CustomizeWindowHint | Qt.WindowStaysOnTopHint)
# win.setAttribute(Qt.WA_TranslucentBackground)
# rendering Images
# win.exitBtn.setIcon(QIcon(":/exit/exit.png"))
# win.exitBtn.setText("")
# handling events
win.setMouseTracking(True)
win.header.mouseReleaseEvent = mouseReleaseEvent
win.header.mousePressEvent = mousePressEvent
win.header.mouseMoveEvent = mouseMoveEvent
# move the Window to top
# topLeftPoint = QApplication.desktop().availableGeometry().topLeft()
# win.move(topLeftPoint)
getAlowedMoves()
setAlowedMovesInUi()
def setAlowedMovesInUi() :
for carac in allKeysList :
getattr(win, carac+"Btn").setChecked(False)
for carac in alowedMoves :
getattr(win, carac+"Btn").setChecked(True)
def getAlowedMoves() :
global alowedMoves
if path.exists("./config/config.json"):
try:
with open("./config/config.json", "r") as f :
data = json.loads(f.read())
if len(data["moves"]) != "0":
alowedMoves = data["moves"]
except Exception:
pass
def saveKeys(moves, setToUi) :
global alowedMoves
alowedMoves = moves
data = {}
data["moves"] = moves
with open("./config/config.json", "w") as f :
f.write(json.dumps(data))
if setToUi :
setAlowedMovesInUi()
def changeAlowedKeys() :
global alowedMoves
alowedMoves = []
for key in allKeysList :
if (getattr(win, key+"Btn").isChecked()) :
alowedMoves.append(key)
saveKeys(alowedMoves, False)
def mousePressEvent(event):
win._old_pos = event.pos()
def mouseReleaseEvent(event):
win._old_pos = None
def mouseMoveEvent(event):
try:
if not win._old_pos:
return
delta = event.pos() - win._old_pos
win.move(win.pos() + delta)
except :
pass
def minimize():
"""
Minimizes the window by calling the showMinimized() method of the `win` object.
"""
win.showMinimized()
endProgramme = False
KEYBOARD = keyboard.Controller()
MOUSE = mouse.Controller()
listener = keyboard.Listener(on_press=on_press)
listener.start()
App = QApplication([])
win = loadUi("./ui/main.ui")
alowedMoves = ["Z", "Q", "S", "D", "Space"]
allKeysList = ["Z", "Q", "S", "D", "Space", "W", "A"]
initWin(winTitle="Anti AFK")
for carac in allKeysList:
getattr(win, carac+"Btn").stateChanged.connect(changeAlowedKeys)
mainThread = None
win.startBtn.clicked.connect(main)
win.stopBtn.clicked.connect(stopMain)
win.startWithoutTimerBtn.clicked.connect(main)
win.minimizeBtn.clicked.connect(minimize)
win.exitBtn.clicked.connect(_exit)
win.azertyPreset.clicked.connect(lambda: saveKeys(["Z", "Q", "S", "D", "Space"], True))
win.qwertyPreset.clicked.connect(lambda: saveKeys(["W", "A", "S", "D", "Space"], True))
win.resetPreset.clicked.connect(lambda: saveKeys([], True))
win.show()
App.exec()