D
D
Dmitry Krasnov2016-12-20 16:55:49
Python
Dmitry Krasnov, 2016-12-20 16:55:49

How to pass a keyboard shortcut to the console in Python?

The crux of the matter is this. There was a need to transfer commands to the console. I sent text commands using the os module. A process has started in the console, so I can’t send commands, I need to send a key combination to the console, for example, ctrl + c

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey K, 2016-12-20
@mututunus

import signal
import subprocess

proc = subprocess.Popen('<some command>', shell=True)
proc.send_signal(signal.SIGINT)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question