-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoIdle.py
More file actions
108 lines (92 loc) · 3.55 KB
/
NoIdle.py
File metadata and controls
108 lines (92 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import ctypes
import time
import random
import argparse
import os
import signal
import sys
# Try to import the winsound module
try:
import winsound
except ImportError:
winsound = None
# Load the user32.dll library
user32 = ctypes.windll.user32
# Define the input structure
class KEYBDINPUT(ctypes.Structure):
_fields_ = [("wVk", ctypes.c_ushort),
("wScan", ctypes.c_ushort),
("dwFlags", ctypes.c_ulong),
("time", ctypes.c_ulong),
("dwExtraInfo", ctypes.POINTER(ctypes.c_ulong))]
class INPUT(ctypes.Structure):
class _INPUT(ctypes.Union):
_fields_ = [("ki", KEYBDINPUT)]
_anonymous_ = ("_input",)
_fields_ = [("type", ctypes.c_ulong), ("_input", _INPUT)]
# Pool of nice messages about Microsoft Technical Trainers
messages = [
"MTTs rule in learning!",
"Your dedication to teaching is inspiring!",
"You are a true expert in tech education!",
"You make complex topics easy to understand!",
"Your training sessions are always engaging!",
"Thank you for your invaluable guidance!",
"Your expertise makes a huge difference!",
"Learning from you is always a pleasure!",
"Awesome trainers like you are rare gems!",
"You are the best of the best in tech training!",
"Your training sessions are always top-notch!",
"You are a true master of tech education!",
"Your passion for teaching is truly remarkable!",
"You are the cornerstone of tech education!",
"Your passion for teaching is contagious!",
"Your training skills are second to none!",
"You are transforming tech training for the better!",
"Keep up the amazing work!"
]
def simulate_mouse_move():
# Move the mouse to a random nearby position with larger movements
x = random.randint(-100, 100)
y = random.randint(-100, 100)
user32.mouse_event(0x0001, x, y, 0, 0)
def print_message():
# Print a random message from the pool to the console
text = random.choice(messages)
print(text+"\n")
def make_beep():
# Make a beep sound
if winsound is not None:
try:
winsound.Beep(1000, 200) # Frequency 1000 Hz, Duration 200 ms
except RuntimeError:
pass # Ignore the error if the beep can't be played
def clear_console():
os.system('cls' if os.name == 'nt' else 'clear')
def signal_handler(sig, frame):
print("\n\nExiting gracefully. Until next time...")
sys.exit(0)
def prevent_idle(beep=False, interval_seconds=30):
while True:
# Clear the console and print a message
clear_console()
print_message()
# Countdown timer
for i in range(interval_seconds, 0, -1):
print(f"\rNext event in T-{i} seconds...", end="")
time.sleep(1)
# Simulate mouse movement
simulate_mouse_move()
if beep:
make_beep()
if __name__ == "__main__":
# Parse command-line arguments
parser = argparse.ArgumentParser(description="Prevent the computer from becoming idle by simulating user input.")
parser.add_argument('--beep', dest='beep', action='store_true', help="Enable beep sound")
parser.add_argument('--interval', type=int, default=30, help="Set the interval in seconds between actions (default: 30 seconds)")
args = parser.parse_args()
# Handle graceful exit
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
# Run the prevent_idle function with the provided or default parameters
prevent_idle(beep=args.beep, interval_seconds=args.interval)