/
trigger.py
57 lines (50 loc) · 1.66 KB
/
trigger.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
import numpy as np
from PIL import ImageGrab
from cv2 import cvtColor, COLOR_BGR2GRAY, Canny
import time
import keyboard
import winsound
from directkeys import PressKey, ReleaseKey
screenShot = ImageGrab.grab()
HALF_WIDTH = screenShot.size[0]/2
HALF_HEIGHT = screenShot.size[1]/2
HOTKEY = 'shift+z'
FIRE_KEY = 0x18 #key codes --> https://msdn.microsoft.com/en-us/library/windows/desktop/bb321074(v=vs.85).aspx
SHOTS_NUMBER = 5 #different on each weapon
del screenShot
isEnabled = False
def inverseIsEnabled():
global isEnabled
if isEnabled:
winsound.Beep(1000, 200)
print('Disabled')
isEnabled = False
else:
winsound.Beep(500, 200)
print('Enabled')
isEnabled = True
#Detect edges in image
def processImg(image):
return Canny(cvtColor(image, COLOR_BGR2GRAY), threshold1=200, threshold2=300)
def makeFire():
for x in range(SHOTS_NUMBER):
PressKey(FIRE_KEY)
time.sleep(0.1)
ReleaseKey(FIRE_KEY)
time.sleep(0.05)
del x
def takeCrosshair():
return np.array(ImageGrab.grab(bbox=(HALF_WIDTH-10, HALF_HEIGHT-10, HALF_WIDTH+10, HALF_HEIGHT+10)))
def trigger():
while True:
if isEnabled:
crosshair1 = processImg(takeCrosshair())
time.sleep(0.00000000001)
crosshair2 = processImg(takeCrosshair())
if (crosshair1 != crosshair2).any():
makeFire()
inverseIsEnabled()
if __name__ == '__main__':
keyboard.add_hotkey(HOTKEY, inverseIsEnabled)
print('Press '+HOTKEY+' to enable cheat for '+str(SHOTS_NUMBER)+' shots')
trigger()