-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
86 lines (55 loc) · 2.11 KB
/
main.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
from ultralytics import YOLO
import cv2
import numpy as np
import mss
from pynput.keyboard import Controller as KeyboardController
import win32gui
def get_active_window_title():
return win32gui.GetWindowText(win32gui.GetForegroundWindow())
def triggerbot():
model = YOLO("train9/weights/best.pt")
sct = mss.mss()
monitor = sct.monitors[1]
screen_width = monitor["width"]
screen_height = monitor["height"]
region_width = 320
region_height = 240
region = {
"top": (screen_height - region_height) // 2,
"left": (screen_width - region_width) // 2,
"width": region_width,
"height": region_height,
}
print(f"Capturing region: {region}")
keyboard = KeyboardController()
screen_mid_x = screen_width / 2
screen_mid_y = screen_height / 2
threshold = 10
while True:
active_window = get_active_window_title()
if "VALORANT" in active_window.upper():
print(f"Active window: {active_window}")
screenshot = np.array(sct.grab(region))
frame = cv2.cvtColor(screenshot, cv2.COLOR_BGRA2BGR)
results = model.predict(frame, imgsz=640, conf=0.35,device=0)
for result in results:
for box in result.boxes:
x1, y1, x2, y2 = box.xyxy[0].tolist()
bbox_center_x = (x1 + x2) / 2
bbox_center_y = (y1 + y2) / 2
screen_x = region["left"] + bbox_center_x
screen_y = region["top"] + bbox_center_y
print(f"Detected object at: ({screen_x}, {screen_y})")
if (
abs(screen_x - screen_mid_x) <= threshold
and abs(screen_y - screen_mid_y) <= threshold
):
keyboard.press("p")
keyboard.release("p")
else:
print(f"Active window: {active_window} - valorant not detected")
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
if __name__ == "__main__":
triggerbot()