-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (51 loc) · 1.6 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
# Used to play sounds on alert
from playsound import playsound
# Image Reading
import pytesseract
# Image Processing
import time
# Keyboard Controller
from pynput.keyboard import Key, Controller
# Makes Minecraft Active
import pygetwindow as gw
from PIL import ImageGrab
############################################
# Config Section:
############################################
# Insert whatever array of words you want to process here. Using 'left the game' works, but then you may get false-positives when there isn't room in the server.
triggerList = ['left the game']
# Path of tesseract executable
pyPath = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
soundEnabled = False
soundPath = 'G:\\Downloads\\1_second_tone.mp3'
boundingBox = (2840, 1727, 3780, 1850)
debug = False
############################################
############################################
def autoJoin():
time.sleep(2)
print('Waiting to Join Game')
pytesseract.pytesseract.tesseract_cmd = pyPath
while(True):
cap = ImageGrab.grab(all_screens=True, bbox = boundingBox)
tesstr = pytesseract.image_to_string(cap, lang ='eng')
if debug:
print("Words found in Image:")
print(tesstr)
cap.show()
keyboard = Controller()
if any(word in tesstr for word in triggerList):
print("Found!")
try:
mcWin = gw.getWindowsWithTitle('Minecraft')[0]
mcWin.activate()
keyboard.press(Key.enter)
keyboard.release(Key.enter)
if soundEnabled:
# Uncomment to play sound
print("Playing Sound")
# playsound(soundPath)
except:
print('Could not find any windows named Minecraft')
quit()
autoJoin()