0
from ctypes import *

ok = windll.user32.BlockInput(True)

So I learned that I can block input in windows with that code

Is it disabled when the script ends or when the pc is rebooted?

But instead of blocking all input id like to redirect all inputs to a char as "E" or "5" does anyone know how to do it?

1 Answers1

0

According to [MS.Docs]: BlockInput function:

The system will unblock input in the following cases:

  • The thread that blocked input unexpectedly exits without calling BlockInput with fBlock set to FALSE. In this case, the system cleans up properly and re-enables input.
  • The user presses CTRL+ALT+DEL or the system invokes the Hard System Error modal message box (for example, when a program faults or a device fails).

So, unblocking occurs when the script (Python process (and its main thread) that executes the script) ends.

For generating system events you should check SendInput documentation. For more info, also check [MS.Docs]: About Keyboard Input.

Regarding key "redirection", I don't know a(n easy) way, but it looks like an XY Problem. There should be another (simpler) way of achieving your end goal.

CristiFati
  • 38,250
  • 9
  • 50
  • 87