-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeepawake.py
More file actions
49 lines (41 loc) · 1.52 KB
/
keepawake.py
File metadata and controls
49 lines (41 loc) · 1.52 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
import pyautogui
import sys
import time
import random
# move mouse to keep system awake
def move_mouse(old_pos):
for n in range(1, random.randint(2, 20)):
# define increment to move mouse, and how long to move mouse for
new_pos_delta = gen_random_delta()
move_time = float(1) / random.randint(1, 10)
# generate a new mouse position
new_pos = (old_pos[0] + new_pos_delta[0],
old_pos[1] + new_pos_delta[1])
# regenerate if off-screen
while not pyautogui.onScreen(new_pos):
new_pos_delta = gen_random_delta()
new_pos = (old_pos[0] + new_pos_delta[0],
old_pos[1] + new_pos_delta[1])
# move to new mouse position
pyautogui.moveTo(*new_pos, move_time, pyautogui.easeOutElastic)
# generate random change in mouse x, y
def gen_random_delta():
x = random.randint(10, 100) * (-1 if random.random() > 0.5 else 1)
y = random.randint(10, 100) * (-1 if random.random() > 0.5 else 1)
return (x, y)
# check if mouse not moved since last update
def check_inactive(pos):
time.sleep(30)
return pyautogui.position() == pos
# press non-intrusive keyboard keys
def key_press():
with pyautogui.hold("shift"):
pyautogui.press("f15")
time.sleep(float(1) / random.randint(1, 10))
if __name__ == "__main__":
pyautogui.FAILSAFE = False
while True:
pos = pyautogui.position()
if check_inactive(pos):
key_press()
move_mouse(pos)