John5617

Python Block Keyboard / Mouse Input

Jan 21st, 2021 (edited)
1,260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. # full code in answer to:
  2. # https://stackoverflow.com/questions/65801957/python-block-keyboard-mouse-input/65828426#65828426
  3.  
  4. #### Blocking Keyboard ####
  5. import keyboard
  6.  
  7. #blocks all keys of keyboard
  8. for i in range(150):
  9.     keyboard.block_key(i)
  10.  
  11.  
  12. #### Blocking Mouse-movement ####
  13. import threading
  14. import mouse
  15. import time
  16.  
  17. global executing
  18. executing = True
  19.  
  20. def move_mouse():
  21.     #until executing is False, move mouse to (1,0)
  22.     global executing
  23.     while executing:
  24.         mouse.move(1,0, absolute=True, duration=0)
  25.  
  26. def stop_infinite_mouse_control():
  27.     #stops infinite control of mouse after 10 seconds if program fails to execute
  28.     global executing
  29.     time.sleep(10)
  30.     executing = False
  31.  
  32. threading.Thread(target=move_mouse).start()
  33. threading.Thread(target=stop_infinite_mouse_control).start()
  34.  
  35.  
  36. #### opening the video ####
  37. import subprocess
  38. import pyautogui
  39. import time
  40.  
  41. subprocess.Popen(["C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",])
  42. time.sleep(3)
  43. pyautogui.write('www.youtube.com/watch?v=DLzxrzFCyOs', interval= 0.1)
  44. pyautogui.hotkey('enter')
  45.  
  46.  
  47. #### stops moving mouse to (1,0) after video has been opened
  48. executing = False
  49.  
Add Comment
Please, Sign In to add comment