Send keyboard event using subprocess

I have two python scripts. The first is just a script waiting for user keyboard input. When the user presses a key, he prints the pressed key value.

The second script calls first one through a subprocess using Popen, like this

p = Popen('python first_script.py', shell=True, universal_newlines=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
print p.communicate(input="some value paased through")[0]

I worked when sending string values. But I do not know how to send a keyboard event and how to read it correctly.

+3
source share
1 answer

subprocessby itself does not have the ability to "send keyboard events" (to a subprocess or to any other process). You need other approbations such as this article for Windows.

+2

Source: https://habr.com/ru/post/1760758/


All Articles