-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyautolock.py
67 lines (53 loc) · 1.29 KB
/
pyautolock.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
63
64
65
66
67
"""
pyautogui based remote/face pc lock code.
by RRN.
"""
import cv2
import pyautogui
import time
from time import sleep
global cap,cv2,flag,faces
cap = cv2.VideoCapture(0)
faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
def Check_Face():
print("Check face Activated!")
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Detect faces in the image
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30)
#flags = cv2.CV_HAAR_SCALE_IMAGE
)
print("Checking for User Presence...")
print("Found {0} faces!".format(len(faces)))
if(len(faces)==0):
print("Detecting no User! Flag set to 0")
flag=0
print(flag)
else:
print("flag set to 1!")
flag=1
print(flag)
return flag
def Execute_Lock():
print("Execute Lock Activated!")
pyautogui.hotkey('win', 'r')
pyautogui.typewrite("cmd\n")
sleep(0.500)
pyautogui.typewrite("rundll32.exe user32.dll, LockWorkStation\n exit\n")
while(True):
time.sleep(5)
Check_Face()
flag = Check_Face()
if flag==0:
#Second Check before trigger
print("No user detected, executing Locking Sequence..")
Execute_Lock()
else:
print("User Detected..Flag reset to 1!")
flag=1
pass
#splash plymouth.ignore-serial-consoles quiet