Created
September 21, 2024 13:58
-
-
Save Rorythedev/6c8a21f58e143fd800d87631ab953474 to your computer and use it in GitHub Desktop.
Macrobot is a easy to use bot for any game by RorytheDev! When you press Ctrl+Shift+R, the script starts recording mouse clicks, mouse movements, and key presses. Each action is timestamped and stored in the macro list. Stop Recording: The script will stop recording when you press the Esc key. Replay Macro: Press Ctrl+Shift+P to replay the recor…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyautogui | |
import keyboard | |
import time | |
import json | |
from datetime import datetime | |
# Store recorded events | |
macro = [] | |
# Record the current time for calculating time differences | |
start_time = None | |
# Start recording the macro | |
def start_recording(): | |
global macro, start_time | |
print("Recording started...") | |
macro = [] | |
start_time = datetime.now() | |
while True: | |
# Record mouse position and click events | |
if keyboard.is_pressed("esc"): # Press 'esc' to stop recording | |
break | |
x, y = pyautogui.position() | |
current_time = (datetime.now() - start_time).total_seconds() | |
if pyautogui.mouseDown(): | |
event = {"type": "mouse_down", "x": x, "y": y, "time": current_time} | |
macro.append(event) | |
print(f"Mouse down at {x}, {y} recorded at {current_time}s") | |
time.sleep(0.1) | |
if pyautogui.mouseUp(): | |
event = {"type": "mouse_up", "x": x, "y": y, "time": current_time} | |
macro.append(event) | |
print(f"Mouse up at {x}, {y} recorded at {current_time}s") | |
time.sleep(0.1) | |
# Record keyboard events | |
for key in keyboard.get_hotkey_name().split("+"): | |
if keyboard.is_pressed(key): | |
event = {"type": "key_press", "key": key, "time": current_time} | |
macro.append(event) | |
print(f"Key '{key}' pressed at {current_time}s") | |
time.sleep(0.1) | |
print("Recording stopped.") | |
save_macro("macro.json") # Save macro to file for replay | |
# Save macro to file | |
def save_macro(file_name): | |
with open(file_name, 'w') as f: | |
json.dump(macro, f) | |
print(f"Macro saved to {file_name}.") | |
# Load macro from file | |
def load_macro(file_name): | |
global macro | |
with open(file_name, 'r') as f: | |
macro = json.load(f) | |
print(f"Macro loaded from {file_name}.") | |
# Replay the recorded macro | |
def replay_macro(): | |
if not macro: | |
print("No macro loaded.") | |
return | |
print("Replaying macro...") | |
replay_start_time = datetime.now() | |
for event in macro: | |
time.sleep(event["time"] - (datetime.now() - replay_start_time).total_seconds()) | |
if event["type"] == "mouse_down": | |
pyautogui.mouseDown(x=event["x"], y=event["y"]) | |
print(f"Mouse down at {event['x']}, {event['y']} at {event['time']}s") | |
if event["type"] == "mouse_up": | |
pyautogui.mouseUp(x=event["x"], y=event["y"]) | |
print(f"Mouse up at {event['x']}, {event['y']} at {event['time']}s") | |
if event["type"] == "key_press": | |
pyautogui.press(event["key"]) | |
print(f"Key '{event['key']}' pressed at {event['time']}s") | |
# Key bindings for the macro | |
def setup_keybindings(): | |
keyboard.add_hotkey('ctrl+shift+r', start_recording) # Press 'Ctrl+Shift+R' to start recording | |
keyboard.add_hotkey('ctrl+shift+p', replay_macro) # Press 'Ctrl+Shift+P' to replay the macro | |
# Main loop | |
if __name__ == "__main__": | |
setup_keybindings() | |
print("Press Ctrl+Shift+R to start recording a macro.") | |
print("Press Ctrl+Shift+P to play back the recorded macro.") | |
print("Press Esc to stop recording.") | |
while True: | |
# Keep the program running to listen to hotkeys | |
try: | |
time.sleep(1) | |
except KeyboardInterrupt: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This basic macro will work for games that accept standard mouse/keyboard inputs, but be careful if the game has strict anti-cheat systems—using macros in online games might get you banned!