Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pynput.keyboard import Key, Listener
- import time
- import ctypes
- from serial.tools import list_ports # pyserial
- lastKeypressTime = 0
- lastCheckTime = time.time()
- suspicion = 0
- loopInterval = 1
- def on_press(key):
- global lastKeypressTime
- lastKeypressTime = time.time()
- def on_release(key):
- global suspicion
- timeSinceLastKeypress = time.time() - lastKeypressTime
- if timeSinceLastKeypress == 0:
- timeSinceLastKeypress = 0.001
- suspicion += 0.005 / timeSinceLastKeypress
- duckhuntcheck()
- def detectKeyboard():
- try:
- value = set([item for item in list_ports.comports()])
- return False
- except:
- return True
- def duckhuntcheck():
- global suspicion, lastCheckTime
- currentTime = time.time()
- timeSinceLastCheck = currentTime - lastCheckTime
- suspicion -= timeSinceLastCheck * 100
- if detectKeyboard():
- suspicion += 1
- if suspicion < 0:
- suspicion = 0
- print(suspicion)
- if suspicion >= 32:
- ctypes.windll.user32.LockWorkStation()
- suspicion = 0
- lastCheckTime = currentTime
- # Collect events until released
- with Listener(
- on_press=on_press,
- on_release=on_release) as listener:
- listener.join()
Advertisement
Add Comment
Please, Sign In to add comment