Advertisement
Python253

simulate_movement

May 10th, 2024
838
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.68 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: simulate_movement.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. This script emulates user interaction by automatically moving the cursor on the screen at predefined intervals.
  9. It serves as a tool for mimicking user activity in scenarios such as preventing system idle timeouts, maintaining application sessions, or testing user interface responsiveness.
  10.  
  11. Requirements:
  12.    - Python must be installed on the system.
  13.    - The pyautogui library must be installed.
  14.      You can install it using this pip command:
  15.              
  16.              'pip install pyautogui'
  17.              
  18.    - The script should be executed on a platform that supports graphical interfaces, such as Windows, macOS, or Linux with X11.
  19.  
  20. Functions:
  21.    - simulate_activity():
  22.      This function continuously moves the cursor in a tiny square pattern at predefined intervals, effectively simulating user activity.
  23.  
  24. Usage:
  25.    1. Ensure Python and the pyautogui library are installed on your system.
  26.    2. Download the simulate_movement.py script to a location on your computer.
  27.    3. Open a command prompt or terminal window.
  28.    4. Navigate to the directory where the script is located.
  29.    5. Run the script by executing the command: python simulate_movement.py.
  30.    6. The script will start simulating cursor movement in the background.
  31.    7. To stop the script, press Ctrl+C in the command prompt or terminal window.
  32.  
  33. Additional Notes:
  34.    - This script is intended for scenarios where it's necessary to prevent system idle timeouts, maintain active sessions, or test user interface responsiveness.
  35.    - Adjustments to the movement step size (MOVEMENT_STEP) and delay (MOVEMENT_DELAY) can be made to customize the behavior of cursor movement.
  36.    - While running, the script does not produce any visible output or indication of activity, making it discreet and suitable for background operation.
  37. """
  38.  
  39. import time
  40. import pyautogui
  41.  
  42. # Constants
  43. SLEEP_DURATION = 60  # Seconds
  44. MOVEMENT_STEP = 1  # Pixels
  45. MOVEMENT_DELAY = 0.0001  # Seconds
  46.  
  47. # Loop indefinitely until interrupted
  48. try:
  49.     while True:
  50.         # Sleep for the specified duration
  51.         time.sleep(SLEEP_DURATION)
  52.        
  53.         # Move the cursor in a tiny square pattern
  54.         pyautogui.move(-MOVEMENT_STEP, 0, duration=MOVEMENT_DELAY)  # Left
  55.         pyautogui.move(0, -MOVEMENT_STEP, duration=MOVEMENT_DELAY)  # Up
  56.         pyautogui.move(MOVEMENT_STEP, 0, duration=MOVEMENT_DELAY)   # Right
  57.         pyautogui.move(0, MOVEMENT_STEP, duration=MOVEMENT_DELAY)   # Down
  58.        
  59. except KeyboardInterrupt:
  60.     # Handle keyboard interrupt (Ctrl+C)
  61.     print("Script terminated by user.")
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement