gpt4 book ai didi

python - 如何让pynput按下回车键,或其他一些按下回车的代码行

转载 作者:行者123 更新时间:2023-12-04 11:30:48 25 4
gpt4 key购买 nike

输入每个 0 后,我想要它,所以它会在之后按 Enter,我尝试了不同的行,但没有,我是一个完整的初学者,请帮助。

from pynput.keyboard import Key, Controller

import time

keyboard = Controller()

time.sleep(1)

for char in " 0 0 0 0 0 0 0":

keyboard.press('0')

keyboard.release('0')

time.sleep(0.25)

最佳答案

enterpynput和你做的类似,见here从文档。您可能想要执行以下操作。

word = " 0 0 0 0 0 0 0"
for i, char in enumerate(word):
if char == "0":
keyboard.press('0')
keyboard.release('0')

#last iteration
if char == "0" and len(word)-1 == i:
keyboard.press(Key.enter)
keyboard.release(Key.enter)
break #break the loop here

关于python - 如何让pynput按下回车键,或其他一些按下回车的代码行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61554410/

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