-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenLockStopper.py
62 lines (43 loc) · 1.34 KB
/
screenLockStopper.py
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
'''
###This is a Screen Lock Preventer###
---------------------------------------
#How to use:
Place the __ScrnLockStopper decorator
to whichever function you would like
to run continuously
---------------------------------------
---------------------------------------
#Example:
#Function want to be ran indefinitely:
def RunMeForever():
print('running indefinitely unless Ctrl + C')
While True:
pass
#Add decorator
import ScreenLockStopper as SLS
@SLS.__ScrnLockStopper
def RunMeForever():
print('running indefinitely unless Ctrl + C')
While True:
pass
Now your function will run indefinitely without
worrying about it falling asleep
---------------------------------------
Reference:
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate
'''
import ctypes
def _SetThreadState(states):
ctypes.windll.kernel32.SetThreadExecutionState(states)
def __ScrnLockStopper(func,
SysStatContinue=0x80000000,
SysStateRequire=0x00000001,
SysScreenUp=0x00000002):
def inside(*args, **kwargs):
_SetThreadState(SysStatContinue | SysStateRequire | SysScreenUp)
ExpectResult = func(*args, **kwargs)
return ExpectResult
return inside
@__ScrnLockStopper
def run():
print("ctrl c to stop")s