Guest User

Untitled

a guest
Jun 26th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. from pynput.keyboard import Key, Listener
  2. import time
  3. import ctypes
  4. from serial.tools import list_ports # pyserial
  5.  
  6. lastKeypressTime = 0
  7. lastCheckTime = time.time()
  8. suspicion = 0
  9. loopInterval = 1
  10.  
  11. def on_press(key):
  12. global lastKeypressTime
  13. lastKeypressTime = time.time()
  14.  
  15. def on_release(key):
  16. global suspicion
  17. timeSinceLastKeypress = time.time() - lastKeypressTime
  18.  
  19. if timeSinceLastKeypress == 0:
  20. timeSinceLastKeypress = 0.001
  21.  
  22. suspicion += 0.005 / timeSinceLastKeypress
  23.  
  24. duckhuntcheck()
  25.  
  26. def detectKeyboard():
  27. try:
  28. value = set([item for item in list_ports.comports()])
  29. return False
  30. except:
  31. return True
  32.  
  33. def duckhuntcheck():
  34. global suspicion, lastCheckTime
  35. currentTime = time.time()
  36. timeSinceLastCheck = currentTime - lastCheckTime
  37.  
  38. suspicion -= timeSinceLastCheck * 100
  39.  
  40. if detectKeyboard():
  41. suspicion += 1
  42.  
  43. if suspicion < 0:
  44. suspicion = 0
  45.  
  46. print(suspicion)
  47.  
  48. if suspicion >= 32:
  49. ctypes.windll.user32.LockWorkStation()
  50. suspicion = 0
  51.  
  52. lastCheckTime = currentTime
  53.  
  54. # Collect events until released
  55. with Listener(
  56. on_press=on_press,
  57. on_release=on_release) as listener:
  58. listener.join()
Advertisement
Add Comment
Please, Sign In to add comment