Skip to content

Instantly share code, notes, and snippets.

@FireStacks
Created April 26, 2024 11:26
Show Gist options
  • Select an option

  • Save FireStacks/5b83060b80b559667613bcc3245855fe to your computer and use it in GitHub Desktop.

Select an option

Save FireStacks/5b83060b80b559667613bcc3245855fe to your computer and use it in GitHub Desktop.
Anti afk basic code

Antiafk code simple and easy

How to use this script:

  1. Copy code from here and paste in any IDE of your choice
  2. Make sure that you can run a python file
  3. To stop it press enter on keyboard or "-" in terminal
import pyautogui
import random
import threading
import time
import keyboard

def move_mouse():
    screen_width, screen_height = pyautogui.size()
    while not stop_event.is_set():
        x = random.randint(0, screen_width)
        y = random.randint(0, screen_height)
        pyautogui.moveTo(x, y, duration=0.5)
        time.sleep(5) 

def stop_on_key_press():
    print("Press - to stop the anti-AFK program...")
    keyboard.wait('-')
    print("Stopping the anti-AFK program...")
    stop_event.set()

stop_event = threading.Event()

pyautogui.FAILSAFE = False  
pyautogui.PAUSE = 0  
pyautogui.moveTo(1, 1)  

move_thread = threading.Thread(target=move_mouse)
move_thread.start()

stop_thread = threading.Thread(target=stop_on_key_press)
stop_thread.start()
  1. Make sure to install the KEYBOARD and AUTOGUI librarys for it to work
pip install pyautogui keyboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment