如何在 Python 中包含"enter key"


import subprocess
path = '/home/test/net.keystore'
text = subprocess.Popen(['keytool', '-list', '-v', '-keystore', path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
file = text.stdout.read().decode().splitlines()
print file

通过子进程 I 尝试获取密钥库证书详细信息 I不知道密钥库的密码。如果我按两次"回车键",那么输出正在处理中

有没有办法在python中自动化"输入密钥"?

您可以使用keyboard模块,您可以使用带有命令python -m pip install keyboardpip进行安装。

以下代码将按回车键:

from keyboard import press
press('enter')

这个安装过程对我有用: C:Python3>pip.exe install keyboard

import keyboard
keyboard.press_and_release('enter')

我使用了Win10,一个简单的按下('enter'(只是停用了活动按钮,但按下并释放有效。python3pythonpresskey

您可以使用:

from selenium.webdriver import ActionChains
ActionChains(self.driver).send_keys(Keys.ENTER).perform()

最新更新