当我尝试使用 pyautogui click 功能运行我的代码时出现错误
Posted
技术标签:
【中文标题】当我尝试使用 pyautogui click 功能运行我的代码时出现错误【英文标题】:Getting Error when I try to run my code with pyautogui click function 【发布时间】:2021-12-30 16:15:28 【问题描述】:我是 python 初学者,我正在制作一个小脚本/宏,当我按 q 时执行特定命令。在这种情况下,它应该只按 2 次双击并按 1,但由于某种原因,当我添加 pyautogui.click(clicks=2, intervals=0.25)
function 时,它破坏了我的代码
from pynput.keyboard import Key, Listener
import pyautogui
from pynput import keyboard
def action():
pyautogui.press("2")
pyautogui.click(clicks=2, intervals=0.25)
pyautogui.press("1")
def on_press(key):
try:
if key.char == "q":
action()
except AttributeError:
pass
def Stop_listner(key):
if key == Key.esc:
return False
# Collect keyboard inputs
with Listener(on_press=on_press, on_release=Stop_listner) as listener:
listener.join()
错误:
C:\Users\sanch\AppData\Local\Programs\Python\Python39\python.exe C:/Users/sanch/PycharmProjects/pythonProject/ThrowAwayProjects/ideas.py
Unhandled exception in listener callback
Traceback (most recent call last):
File "C:\Users\sanch\AppData\Local\Programs\Python\Python39\lib\site-packages\pynput\_util\__init__.py", line 211, in inner
return f(self, *args, **kwargs)
File "C:\Users\sanch\AppData\Local\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_win32.py", line 284, in _process
self.on_press(key)
File "C:\Users\sanch\AppData\Local\Programs\Python\Python39\lib\site-packages\pynput\_util\__init__.py", line 127, in inner
if f(*args) is False:
File "C:\Users\sanch\PycharmProjects\pythonProject\ThrowAwayProjects\ideas.py", line 13, in on_press
action()
File "C:\Users\sanch\PycharmProjects\pythonProject\ThrowAwayProjects\ideas.py", line 7, in action
pyautogui.click(clicks=2, intervals=0.25)
File "C:\Users\sanch\AppData\Local\Programs\Python\Python39\lib\site-packages\pyautogui\__init__.py", line 586, in wrapper
returnVal = wrappedFunction(*args, **kwargs)
TypeError: click() got an unexpected keyword argument 'intervals'
Traceback (most recent call last):
File "C:\Users\sanch\PycharmProjects\pythonProject\ThrowAwayProjects\ideas.py", line 23, in <module>
listener.join()
File "C:\Users\sanch\AppData\Local\Programs\Python\Python39\lib\site-packages\pynput\_util\__init__.py", line 259, in join
six.reraise(exc_type, exc_value, exc_traceback)
File "C:\Users\sanch\AppData\Local\Programs\Python\Python39\lib\site-packages\six.py", line 718, in reraise
raise value.with_traceback(tb)
File "C:\Users\sanch\AppData\Local\Programs\Python\Python39\lib\site-packages\pynput\_util\__init__.py", line 211, in inner
return f(self, *args, **kwargs)
File "C:\Users\sanch\AppData\Local\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_win32.py", line 284, in _process
self.on_press(key)
File "C:\Users\sanch\AppData\Local\Programs\Python\Python39\lib\site-packages\pynput\_util\__init__.py", line 127, in inner
if f(*args) is False:
File "C:\Users\sanch\PycharmProjects\pythonProject\ThrowAwayProjects\ideas.py", line 13, in on_press
action()
File "C:\Users\sanch\PycharmProjects\pythonProject\ThrowAwayProjects\ideas.py", line 7, in action
pyautogui.click(clicks=2, intervals=0.25)
File "C:\Users\sanch\AppData\Local\Programs\Python\Python39\lib\site-packages\pyautogui\__init__.py", line 586, in wrapper
returnVal = wrappedFunction(*args, **kwargs)
TypeError: click() got an unexpected keyword argument 'intervals'
Process finished with exit code 1
【问题讨论】:
请添加错误详情 【参考方案1】:看起来pyautogui.click()
不喜欢intervals=0.25
。试试:
pyautogui.click(clicks=2, interval=0.25)
将“间隔”选项更改为“间隔”
【讨论】:
以上是关于当我尝试使用 pyautogui click 功能运行我的代码时出现错误的主要内容,如果未能解决你的问题,请参考以下文章