How can I catch a key press in my program, but it won't be caught by other applications?
I know this is possibly a dupe of Is it possible to intercept key presses with python? but I did not find any descriptive answers in there.
How can I catch a key press in my program, but it won't be caught by other applications?
I know this is possibly a dupe of Is it possible to intercept key presses with python? but I did not find any descriptive answers in there.
Interesting idea. We could create a quick "key-logger" script in Python using the pynput library. The implementation is pretty simple and only entails the following lines of code (taken from the docs).
def on_press(key):
try:
print('alphanumeric key {0} pressed'.format(
key.char))
except AttributeError:
print('special key {0} pressed'.format(
key))
listener = keyboard.Listener(on_press=on_press)
listener.start()
This gif shows how this would run.
However if you were looking for key presses to be entirely redirected to a Python program, then the solution will probably be more involved and probably entail some fiddling with the keyboard buffer.