Python: How to generate a keypress?

I start a process (with os.popen ()) which detects certain keystrokes for some commands (eg ESC - not character, key). Is there a way to send keypress events to a process?

+1


source to share


3 answers


You probably want something like Pexpect

. It's been a while and there may be a better alternative now, but it will allow you to do what you want.



As far as I know, there is no easy way to do this with os.popen or commands in a module subprocess

.

+1


source


The obvious way would be to start the process in its own shell.
something like os.popen ("sh" command)



0


source


What platform is it on?

You may need to pass events to the event loop if it runs on Win32.

0


source







All Articles