-
Notifications
You must be signed in to change notification settings - Fork 11
/
autoskill.py
63 lines (49 loc) · 1.74 KB
/
autoskill.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
import cv2
import numpy as np
import pyautogui
import pyscreenshot as ImageGrab
import json
import time
import ctypes
from colorama import init, Fore
TARGET_PID = 4388
init(autoreset=True) # Initialize colorama
def load_config():
with open("config.json", "r") as f:
return json.load(f)
def find_image_on_screen(template, threshold=0.9):
screenshot = ImageGrab.grab()
screen = cv2.cvtColor(np.array(screenshot), cv2.COLOR_RGB2BGR)
result = cv2.matchTemplate(screen, template, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
if max_val >= threshold:
return max_loc
return None
def is_target_window_active():
GetForegroundWindow = ctypes.windll.user32.GetForegroundWindow
GetWindowThreadProcessId = ctypes.windll.user32.GetWindowThreadProcessId
hwnd = GetForegroundWindow()
pid = ctypes.wintypes.DWORD()
GetWindowThreadProcessId(hwnd, ctypes.pointer(pid))
return pid.value == TARGET_PID
def main():
config = load_config()
while True:
if not is_target_window_active():
print(Fore.YELLOW + "Target window is not active")
time.sleep(1)
continue
match_found = False
for match in config["matches"]:
if not match["enabled"]:
continue
image = cv2.imread(match["image"], cv2.IMREAD_COLOR)
if find_image_on_screen(image) is not None:
match_found = True
print(Fore.GREEN + f"Match found for {match['image']}, pressing key {match['key']}")
pyautogui.press(match["key"])
if not match_found:
print(Fore.RED + "No match found")
time.sleep(0.1)
if __name__ == "__main__":
main()