Skip to content

Instantly share code, notes, and snippets.

@lukifer195
Created July 30, 2020 07:35
Show Gist options
  • Save lukifer195/e858a0d15df3727b67a16d3931ef2b3e to your computer and use it in GitHub Desktop.
Save lukifer195/e858a0d15df3727b67a16d3931ef2b3e to your computer and use it in GitHub Desktop.
Hook mouse & keyboard and hide all interface apps window until recognize pass(5s unlock)
import pythoncom, pyHook
import time
import win32api
import win32gui
import win32con
import threading
import sys
isStop = False
list_wd = []
def hide_show(hwnd, isShow):
hwnd = win32gui.FindWindow(None, hwnd)
if isShow == 'hide':
win32gui.ShowWindow(hwnd, win32con.SW_HIDE)
# print('hide:' , win32gui.GetWindowText(hwnd))
elif isShow == 'show':
win32gui.ShowWindow(hwnd, win32con.SW_SHOW)
print('show:' , win32gui.GetWindowText(hwnd))
def enumHandler(hwnd, lParam):
global list_wd
if win32gui.IsWindowVisible(hwnd):
if win32gui.GetWindowText(hwnd) :
print(hwnd , "\t" , win32gui.GetWindowText(hwnd))
list_wd.append(hwnd)
def Recognize():
"""reconize face return isStop """
global isStop
time.sleep(5)
win32gui.EnumWindows(enumHandler, None)
for x in list_wd:
hide_show(win32gui.GetWindowText(x) , 'show')
isStop = True
def doHook(event):
print(isStop)
if isStop == False:
return False
else:
sys.exit()
def start_hook():
hm = pyHook.HookManager()
hm.MouseAll = doHook
hm.KeyAll = doHook
hm.HookMouse()
hm.HookKeyboard()
pythoncom.PumpMessages()
print('start')
if __name__ == '__main__':
class doHide(threading.Thread):
def __init__(self, data):
super().__init__()
self.data = data
def run(self):
print('Thread doHide running')
win32gui.EnumWindows(enumHandler, None)
for x in list_wd:
hide_show(win32gui.GetWindowText(x) , 'hide')
start_hook()
class doRecognize(threading.Thread):
def __init__(self, data):
super().__init__()
self.data = data
def run(self):
print('Thread doRecognize running')
Recognize()
thread_start_doHide_hooking = doHide(1)
thread_recognize_doshow = doRecognize(1)
thread_start_doHide_hooking.start()
thread_recognize_doshow.start()
thread_start_doHide_hooking.join()
thread_recognize_doshow.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment