Untitled

mail@pastecode.io avatar
unknown
python
2 months ago
3.1 kB
2
Indexable
Never
import random
import time
import threading
import pyautogui
import json
from tkinter import *
from tkinter import messagebox
import logging

# Configure logging
logging.basicConfig(filename='script_activity.log', level=logging.INFO, format='%(asctime)s:%(levelname)s:%(message)s')

def parse_duration(duration_str):
  unit = duration_str[-1].lower()
  duration = int(duration_str[:-1])
  if unit == 'h':
    return duration * 60 * 60
  elif unit == 'm':
    return duration * 60
  elif unit == 's':
    return duration
  else:
    return duration * 60  # Default to hours

def load_config(config_file):
  try:
    with open(config_file, 'r') as f:
      return json.load(f)
  except FileNotFoundError:
    logging.warning(f"Config file '{config_file}' not found. Using defaults.")
    return {
      "min_alt_tab_delay": 30,
      "max_alt_tab_delay": 75,
      "min_mouse_delay": 30,
      "max_mouse_delay": 60,
      "randomize_xy": True,
      "kill_switch_key": "esc"
    }
  except json.JSONDecodeError:
    logging.error("Invalid configuration file format. Using defaults.")
    return {
      "min_alt_tab_delay": 30,
      "max_alt_tab_delay": 75,
      "min_mouse_delay": 30,
      "max_mouse_delay": 60,
      "randomize_xy": True,
      "kill_switch_key": "esc"
    }

def save_config(config, config_file):
  try:
    with open(config_file, 'w') as f:
      json.dump(config, f, indent=4)
    logging.info(f"Configuration saved to '{config_file}'.")
  except Exception as e:
    logging.error(f"Failed to save configuration: {e}")
    messagebox.showerror("Error", "Failed to save configuration file.")

def validate_config(config):
  valid = True
  try:
    if not isinstance(config['min_alt_tab_delay'], int) or config['min_alt_tab_delay'] < 0:
      raise ValueError("min_alt_tab_delay must be a non-negative integer")
    if not isinstance(config['max_alt_tab_delay'], int) or config['max_alt_tab_delay'] <= config['min_alt_tab_delay']:
      raise ValueError("max_alt_tab_delay must be a positive integer greater than min_alt_tab_delay")
    # Similar validation for other config values
  except ValueError as e:
    logging.error(f"Invalid configuration: {e}")
    messagebox.showerror("Error", "Invalid configuration values. Please check the log for details.")
    valid = False
  return valid

def alt_tab():
  while running:
    try:
      delay = random.randint(min_alt_tab_delay.get(), max_alt_tab_delay.get())
      time.sleep(delay)
      logging.info(f"Performing Alt+Tab action (delay: {delay} seconds)")
      pyautogui.hotkey('alt', 'tab')
    except pyautogui.Exception as e:
      logging.error(f"Error during Alt+Tab: {e}")

def move_mouse():
  while running:
    try:
      delay = random.randint(min_mouse_delay.get(), max_mouse_delay.get())
      time.sleep(delay)
      if randomize_xy.get():
        x = random.randint(0, 1920)
        y = random.randint(0, 1080)
      else:
        x, y = pyautogui.position()
        offset = 100  # Adjust this value for desired movement range
        new_x = x + random.randint(-offset, offset)
        new_y = y + random.randint(-offset, offset)
        new_x = max
Leave a Comment