Change key order in combo_keys as you like.
Adjust key delay according to cast time average
Python is required.
pip install all libraries below
Tesseract is not required.I tried to add Screen OCR and auto life and mana but not working well so releated codes are commented out
Code:
import keyboard
import time
import cv2
import pytesseract
import pygetwindow as gw
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
# Configuration: Keys in the combo and their delays (in milliseconds)
combo_keys = ["q", "1", "e", "r", "t", "f"]
key_delay = 0.7 # Delay in seconds (500ms)
activation_key = "shift" # Key to activate the combo
pause_key = "7" # Key to pause the combo
resume_key = "8" # Key to resume the combo
life_key = "4" # Key to press if Life is below threshold
mana_key = "5" # Key to press if Mana is below threshold
# Threshold values
life_threshold = 150
mana_threshold = 150
# State variables
is_paused = False
# Function to execute the combo
def execute_combo():
for key in combo_keys:
keyboard.press_and_release(key)
time.sleep(key_delay)
# Function to ensure the game window is focused
# def focus_game_window():
# game_window_name = "Path of Exile 2"
# for window in gw.getAllTitles():
# if game_window_name in window:
# gw.getWindowsWithTitle(window)[0].activate()
# return True
# print("Game window not found or not focused.")
# return False
# Function to extract value from green rectangle using OCR
def extract_value_from_image(image_path):
# Load the image
image = cv2.imread(image_path)
# Convert the image to HSV for color detection
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# Define green color range
green_lower = (40, 50, 50)
green_upper = (90, 255, 255)
# Create mask for green color
green_mask = cv2.inRange(hsv, green_lower, green_upper)
# Find contours for green rectangles
contours, _ = cv2.findContours(green_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# Assume the largest green contour is the box containing the value
if contours:
green_rect = max(contours, key=cv2.contourArea)
x, y, w, h = cv2.boundingRect(green_rect)
# Crop the green rectangle area
cropped_image = image[y:y + h, x:x + w]
# Convert to grayscale for OCR
gray = cv2.cvtColor(cropped_image, cv2.COLOR_BGR2GRAY)
# Perform OCR to extract text
text = pytesseract.image_to_string(gray, config="--psm 7 digits")
try:
# Extract the first numeric value
value = int(text.split('/')[0])
return value
except (ValueError, IndexError):
print("Failed to extract value from OCR.")
return None
else:
print("No green rectangle detected.")
return None
# Function to check Life threshold
# def check_life():
# value = extract_value_from_image("Life.png")
# if value is not None and value < life_threshold:
# keyboard.press_and_release(life_key)
# print("Life is below threshold.")
# Function to check Mana threshold
# def check_mana():
# value = extract_value_from_image("Mana.png")
# if value is not None and value < mana_threshold:
# keyboard.press_and_release(mana_key)
# print("Mana is below threshold.")
# Main loop
print(f"Press '{activation_key}' to trigger the combo...")
print(f"Press '{pause_key}' to pause and '{resume_key}' to resume...")
try:
while True:
if keyboard.is_pressed(pause_key):
is_paused = True
print("Combo paused.")
while keyboard.is_pressed(pause_key):
pass # Wait until the pause key is released
if keyboard.is_pressed(resume_key):
is_paused = False
print("Combo resumed.")
while keyboard.is_pressed(resume_key):
pass # Wait until the resume key is released
if not is_paused:
# if focus_game_window():
if keyboard.is_pressed(activation_key):
execute_combo()
while keyboard.is_pressed(activation_key):
pass # Wait until the activation key is released
# Check Life and Mana from their respective images
# check_life()
# check_mana()
time.sleep(0.1) # Small delay to prevent excessive CPU usage
except KeyboardInterrupt:
print("\nMacro stopped.")