import cv2
import time
import numpy
import ctypes
import win32api
import threading
import dxcam
from multiprocessing import Pipe, Process
from ctypes import windll
def bypass(pipe):
keybd_event = windll.user32.keybd_event
while True:
try:
key = pipe.recv()
if key == b'\x01':
keybd_event(0x4F, 0, 0, 0)
keybd_event(0x4F, 0, 2, 0)
except EOFError:
break
def send_key_multiprocessing(pipe):
pipe.send(b'\x01')
class Triggerbot:
def __init__(self, pipe):
user32 = windll.user32
self.WIDTH, self.HEIGHT = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
self.size = 5
self.Fov = (
int(self.WIDTH / 2 - self.size),
int(self.HEIGHT / 2 - self.size),
int(self.WIDTH / 2 + self.size),
int(self.HEIGHT / 2 + self.size),
)
self.camera = dxcam.create()
self.camera.start(region=self.Fov, target_fps=244)
self.frame = None
self.cmin = (0, 155, 244)
self.cmax = (0, 229, 252)
self.pipe = pipe
self.shoot_delay = 0.01
self.last_shoot_time = time.time() - self.shoot_delay
def Capture(self):
while True:
self.frame = self.camera.get_latest_frame()
time.sleep(0.0041)
def Color(self):
if self.frame is not None:
hsv = cv2.cvtColor(self.frame, cv2.COLOR_RGB2HSV)
mask = cv2.inRange(hsv, self.cmin, self.cmax)
detected = numpy.any(mask)
return detected
else:
return False
def Main(self):
while True:
if win32api.GetAsyncKeyState(0xA4) < 0:
if self.Color():
current_time = time.time()
if current_time - self.last_shoot_time >= self.shoot_delay:
send_key_multiprocessing(self.pipe)
self.last_shoot_time = current_time
time.sleep(0.01)
if __name__ == "__main__":
parent_conn, child_conn = Pipe()
p = Process(target=bypass, args=(child_conn,))
p.start()
triggerbot = Triggerbot(parent_conn)
threading.Thread(target=triggerbot.Capture).start()
threading.Thread(target=triggerbot.Main).start()
p.join()