Python 如何使用pyautogui正确执行按键选项?

Python 如何使用pyautogui正确执行按键选项?,python,loops,pyautogui,Python,Loops,Pyautogui,我正在尝试执行12次。使用pyautogui库在tab按钮上按() 以下是我目前得到的信息: import pyautogui pyautogui.press(['tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab'], 0.01) 这将引发下一个错误: File "path", line 42, in <module> pyautogui.

我正在尝试执行12次
。使用
pyautogui
库在
tab
按钮上按()

以下是我目前得到的信息:

import pyautogui
pyautogui.press(['tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab'], 0.01)
这将引发下一个错误:

  File "path", line 42, in <module>
    pyautogui.press(['tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab'], 0.01)

  File "path", line 586, in wrapper
    returnVal = wrappedFunction(*args, **kwargs)

  File "path", line 1594, in press
    for i in range(presses):
TypeError: 'float' object cannot be interpreted as an integer
文件“路径”,第42行,在
pyautogui。按(['tab','tab','tab','tab','tab','tab','tab','tab','tab','tab','tab'],0.01)
包装器中的文件“路径”,第586行
returnVal=wrappedFunction(*args,**kwargs)
文件“路径”,第1594行,按
对于范围内的i(按):
TypeError:“float”对象不能解释为整数

有没有办法通过使用循环来完成此任务?或者任何其他更简单的方法?

您可以使用for循环,也可以添加一个参数使其成为12。我还假设.01与您想要的间隔相关,这需要间隔关键字

import pyautogui

for x in range(12):
    pyautogui.press('tab', interval=.01)

当你把它们作为一个列表放在press命令中时(就像你以前做的那样),它会尝试同时按下它们,而不是按tab键12次,我想这是你想要的

import pyautogui

pyautogui.press('tab', interval=.01, presses=12)