0

I am creating a bot in Python automating some keyboard and mouse actions for specific apps. I am looking for a way to block user input (mouse and if possible keyboard), but still be able to send hotkeys from pynput library's keyboard module at the same time while the user input block is active.

I know windll BlockInput can block both keyboard and mouse inputs from the user, but it also blocks pynput's keyboard press event as well.

ok = windll.user32.BlockInput(True) #enable block
key_presser.press(keyboard.Key.f12)
ok = windll.user32.BlockInput(False) #disable block
Eray
  • 1
  • 1
  • Have you seen [this answer](https://stackoverflow.com/a/67759903/2280890)? It might be adaptable to your needs. – import random Sep 26 '22 at 04:56
  • The [BlockInput doc](https://learn.microsoft.com/en-au/windows/win32/api/winuser/nf-winuser-blockinput) says that the blocking thread can [send input](https://learn.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-sendinput), but I couldn't get that to work at triggering a pynput event handler. Additionally keypress events were queued until I called `BlockInput(False)` then they triggered the handler. `Ctrl+Alt+Del` will interrupt your input blocking so you might be able to work with that. – import random Oct 01 '22 at 13:28

0 Answers0