gpt4 book ai didi

python - 使用子进程发送键盘事件

转载 作者:行者123 更新时间:2023-11-28 17:54:11 26 4
gpt4 key购买 nike

我有两个 python 脚本。第一个只是等待用户键盘输入的脚本。当用户按下一个键时,它会打印一个按下的键值。

第二个脚本像这样使用 Popen 通过子进程调用第一个脚本

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]

当我发送字符串值时,它开始工作了。但我不知道如何发送键盘事件以及如何正确读取它。

最佳答案

subprocess 本身没有“发送键盘事件”(到子进程或任何其他进程)的设施。您需要其他方法,例如 this article适用于 Windows 的节目。

关于python - 使用子进程发送键盘事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3531953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com