开发者

Send keyboard event using subprocess

开发者 https://www.devze.com 2023-01-12 05:16 出处:网络
I have two python script开发者_开发技巧s. First one is just a script waiting for user keyboard input. When user presses a key it prints a pressed key value.

I have two python script开发者_开发技巧s. First one is just a script waiting for user keyboard input. When user presses a key it prints a pressed key value.

Second script calls first one through 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 got it working when I send through string values. But I don't know how to send keyboard event and how to read it properly.


subprocess per se has no facilities to "send keyboard events" (to the sub-process or to any other process). You need other aproaches, such as the one this article shows for Windows.

0

精彩评论

暂无评论...
验证码 换一张
取 消