Skip to content

Instantly share code, notes, and snippets.

@s0meguy1
Last active October 16, 2024 16:01
Show Gist options
  • Save s0meguy1/c0f26f203aa9b9a32db43cf09efddab6 to your computer and use it in GitHub Desktop.
Save s0meguy1/c0f26f203aa9b9a32db43cf09efddab6 to your computer and use it in GitHub Desktop.
Mouse-movements
import os
import time
import sys
import signal
from datetime import datetime, timedelta
import random
def move_mouse():
"""
Simulates a small mouse movement using arrow keys.
"""
os.system("""
osascript -e 'tell application "System Events" to key code 123'
osascript -e 'tell application "System Events" to key code 124'
""")
def signal_handler(signum, frame):
"""
Handle termination signals
"""
print("\nReceived termination signal. Stopping the script.")
sys.exit(0)
def mouse_jiggler(duration_minutes):
"""
Starts the mouse jiggler for the specified duration.
"""
duration_seconds = duration_minutes * 60
start_time = time.time()
end_datetime = datetime.now() + timedelta(seconds=duration_seconds)
movement_count = 0
print(f"Mouse jiggler started for {duration_minutes} minutes.")
print(f"Expected stop time is: {end_datetime.strftime('%H:%M:%S')}")
print("Press Ctrl+C to stop the script at any time.")
try:
while True:
elapsed_time = time.time() - start_time
remaining_time = duration_seconds - elapsed_time
if remaining_time <= 0:
print("\nDuration completed. Exiting the script.")
break
move_mouse()
movement_count += 1
remaining_minutes = int(remaining_time // 60)
remaining_seconds = int(remaining_time % 60)
print(f"\rMovements: {movement_count}, Time remaining: {remaining_minutes:02d}:{remaining_seconds:02d}", end="", flush=True)
time.sleep(random.uniform(30, 90))
except KeyboardInterrupt:
print("\nScript interrupted manually.")
finally:
print("\nScript stopped.")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python mouse_jiggler.py <duration in minutes>")
print("Valid durations: 10, 15, 30, 60")
sys.exit(1)
try:
duration = int(sys.argv[1])
if duration not in [10, 15, 30, 60]:
raise ValueError
except ValueError:
print("Invalid duration. Use 10, 15, 30, or 60.")
sys.exit(1)
# Set up signal handlers
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
mouse_jiggler(duration)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment