Skip to content

Commit 8370865

Browse files
committed
Fixed major bugs
Major update: Fixed bot not working when taskbar wasn't on the bottom of the screen; Fixed bot not working in windowed mode
1 parent 82f7e42 commit 8370865

File tree

2 files changed

+105
-61
lines changed

2 files changed

+105
-61
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Exe and Testing
2+
csgo-autoaccept-exe/
3+
test.py
4+
15
# Byte-compiled / optimized / DLL files
26
__pycache__/
37
*.py[cod]

csgo-autoaccept-script/bot.py

Lines changed: 101 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,121 @@
1-
from tkinter.messagebox import YESNOCANCEL
2-
from pyautogui import *
3-
import pyautogui
4-
import time
5-
import keyboard
6-
import random
7-
import win32api, win32con
8-
import math
9-
import winsound
1+
import pyautogui, keyboard, win32api, win32con
2+
from math import floor
3+
from time import sleep
4+
from winsound import Beep
5+
import concurrent.futures
106

117

128
def click(x, y):
139
win32api.SetCursorPos((x,y))
1410
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
15-
time.sleep(0.01)
11+
sleep(0.01)
1612
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
1713

1814

1915
def findCSGO():
20-
win32api.SetCursorPos((math.floor(pyautogui.size().width/2),pyautogui.size().height)) #Place cursor on the bottom part of screen to show taskbar if it auto hides
21-
time.sleep(0.5) #Waits for the taskbar animation
22-
try:
23-
#Tries finding the csgo logo and clicks on it
24-
regionLeft = 0
25-
regionTop = math.floor((pyautogui.size().height)-(pyautogui.size().height/5))
26-
regionWidth = pyautogui.size().width
27-
regionHeight = math.floor(pyautogui.size().height/5)
16+
#Defining taskbar locations
17+
bottomTaskbar = (0, floor((pyautogui.size().height)-(pyautogui.size().height/5)), pyautogui.size().width, floor(pyautogui.size().height/5))
18+
leftTaskbar = (0, 0, floor(pyautogui.size().width/5), pyautogui.size().height)
19+
topTaskbar = (0, 0, pyautogui.size().width, floor(pyautogui.size().height/5))
20+
rightTaskbar = (floor((pyautogui.size().width)-(pyautogui.size().width/5)), 0, floor(pyautogui.size().width/5), pyautogui.size().height)
21+
#Adding all taskbar locations to a tuple, and adding a xy coordinate to them
22+
taskbars = ((bottomTaskbar, (floor(pyautogui.size().width/2), pyautogui.size().height-1)),
23+
(leftTaskbar, (1, floor(pyautogui.size().height/2))),
24+
(topTaskbar, (floor(pyautogui.size().width/2), 1)),
25+
(rightTaskbar, (pyautogui.size().width-1, floor(pyautogui.size().height/2))))
2826

29-
click(pyautogui.locateOnScreen('images/csgo.png', region=(regionLeft, regionTop, regionWidth, regionHeight), grayscale=True, confidence=0.8).left, pyautogui.locateOnScreen('images/csgo.png', region=(regionLeft, regionTop, regionWidth, regionHeight), grayscale=True, confidence=0.8).top)
30-
return True
31-
except:
32-
return False
27+
for taskbar, xy in taskbars:
28+
try:
29+
#Placing the cursor on the part of the screen where taskbar should be to show it (if hidden)
30+
win32api.SetCursorPos(xy)
31+
sleep(0.25)
32+
#Looking for the csgo icon on the taskbar
33+
click(pyautogui.locateOnScreen('images/csgo.png', region=taskbar, grayscale=True, confidence=0.8).left, pyautogui.locateOnScreen('images/csgo.png', region=taskbar, grayscale=True, confidence=0.8).top)
34+
return True
35+
except:
36+
continue
37+
38+
print("Couldn't find CS:GO! Make sure the game is running!")
39+
return False
3340

3441

42+
def acceptGame(fullscreen, centerRegion):
43+
print(" > Searching for Accept Button...\n > Hold Left Arrow to stop searching\n\n")
44+
while(True):
45+
if keyboard.is_pressed('right') or keyboard.is_pressed('left'):
46+
print("[Off] AutoAccept")
47+
Beep(400, 400)
48+
return False
49+
50+
if fullscreen:
51+
if(pyautogui.locateOnScreen('images/accept.png', region=centerRegion, grayscale=True, confidence=0.8) != None):
52+
click(pyautogui.locateOnScreen('images/accept.png', region=centerRegion, grayscale=True, confidence=0.8).left, pyautogui.locateOnScreen('images/accept.png', region=centerRegion, grayscale=True, confidence=0.8).top)
53+
print("\nMatch found, [OFF] AutoAccept\nDisabled Keybinds")
54+
return True
55+
56+
else:
57+
if(pyautogui.locateOnScreen('images/accept.png', grayscale=True, confidence=0.8) != None):
58+
click(pyautogui.locateOnScreen('images/accept.png', grayscale=True, confidence=0.8).left, pyautogui.locateOnScreen('images/accept.png', grayscale=True, confidence=0.8).top)
59+
print("\nMatch found, [OFF] AutoAccept\nDisabled Keybinds")
60+
return True
61+
sleep(1)
62+
63+
3564
def main():
36-
found = findCSGO() #continues if csgo logo was clicked
37-
if found:
38-
time.sleep(5)
39-
winsound.Beep(1000, 200)
40-
winsound.Beep(1000, 200)
41-
accept = False
42-
43-
regionLeft = math.floor((pyautogui.size().width/2)/2)
44-
regionTop = 0
45-
regionWidth = math.floor(pyautogui.size().width/2)
46-
regionHeight = pyautogui.size().height
47-
centerRegion = (regionLeft, regionTop, regionWidth, regionHeight)
48-
print("\nBinds\n > Q | Quit")
49-
print(" > U | AutoAccept\n\n")
65+
if findCSGO():
66+
#Setting up variables to find out if user uses Exclusive Fullscreen or Windowed
67+
resolution = pyautogui.size()
68+
fullscreen = False
69+
70+
#Setting up settings bools and areas for searching up images
71+
enableKeybinds = True
72+
centerRegion = (floor((resolution.width/2)/2), 0, floor(resolution.width/2), resolution.height)
73+
74+
#After opening up cs, checking resolution every 500ms to find out if cs runs on a custom resolution or native
75+
for i in range(10):
76+
if resolution != pyautogui.size():
77+
resolution = pyautogui.size()
78+
fullscreen = True
79+
Beep(1000, 500)
80+
Beep(1000, 500)
81+
print(f"Fullscreen Resolution Found! {resolution.width}x{resolution.height}")
82+
break
83+
84+
if i == 9 and resolution == pyautogui.size():
85+
print(f"Didn't find Fullscreen Resolution, using default {pyautogui.size().width}x{pyautogui.size().height}")
86+
Beep(500, 500)
87+
sleep(0.5)
88+
89+
print("\nBinds\n")
90+
print(" > Up Arrow | Enables/Disables Keybinds Below")
91+
print(" > Right Arrow | Quit")
92+
print(" > Left Arrow | AutoAccept\n\n")
5093
print(" Logs \n---------")
5194

5295
while(True):
53-
if keyboard.is_pressed('q'):
54-
return
55-
56-
if keyboard.is_pressed('o'):
57-
print("Screenshotted")
58-
pyautogui.screenshot('scrn.png', region=centerRegion)
59-
60-
if keyboard.is_pressed('u'):
61-
if accept:
62-
winsound.Beep(400, 400)
63-
accept = False
64-
print("[OFF] AutoAccept")
65-
time.sleep(1)
66-
96+
event = keyboard.read_event()
97+
if event.event_type == keyboard.KEY_DOWN and event.name == 'up':
98+
if enableKeybinds:
99+
enableKeybinds = False
100+
print("Disabled Keybinds")
67101
else:
68-
winsound.Beep(800, 400)
69-
accept = True
70-
print("[ON] AutoAccept")
71-
time.sleep(1)
72-
73-
if accept:
74-
if(pyautogui.locateOnScreen('images/accept.png', region=centerRegion, grayscale=True, confidence=0.8) != None):
75-
click(pyautogui.locateOnScreen('images/accept.png', region=centerRegion, grayscale=True, confidence=0.8).left, pyautogui.locateOnScreen('images/accept.png', region=centerRegion, grayscale=True, confidence=0.8).top)
76-
accept = False
77-
print("\nMatch found, [OFF] AutoAccept")
102+
enableKeybinds = True
103+
print("Enabled Keybinds")
104+
105+
if enableKeybinds:
106+
if event.event_type == keyboard.KEY_DOWN and event.name == 'right':
107+
return
78108

109+
elif event.event_type == keyboard.KEY_DOWN and event.name == 'left':
110+
print("[On] AutoAccept")
111+
Beep(800, 400)
112+
if acceptGame(fullscreen, centerRegion):
113+
enableKeybinds = False
114+
115+
79116

80117
if __name__ == '__main__':
81-
main()
118+
with concurrent.futures.ThreadPoolExecutor() as executor:
119+
executor.submit(main)
120+
121+
#pyautogui.screenshot('scrn.png', region=centerRegion)

0 commit comments

Comments
 (0)