为什么我总是让错误消息控制器没有属性is_pressed?
我一直在编码一个非常简单的自动化器。我的自动化器效果很好,但是杀死它的唯一方法是强制关闭我的计算机,因为它点击了如此之快,我无法访问我的任务栏。我可以使它变慢,但是我更喜欢用户使用按钮按下按钮关闭自动化器的一种方法。我已经尝试了如果键盘。IS_PRESSSED('q'):break
,但是我总是会得到错误消息attributeError:'控制器'对象没有属性'is_pressed'。您的意思是:'alt_pressed'?我希望我的代码在按Q时打破循环,但是我会收到一个错误消息。错误消息也将弹出,而无需按Q的按下。到目前为止,我的代码是:
from pynput.mouse import Button, Controller
from pynput.keyboard import Key, Controller
import time
keyboard = Controller()
mouse = Controller()
while True:
time.sleep(10)
mouse.click(Button.left)
if keyboard.is_pressed('q'):
break
I've been coding a very simple autoclicker. My autoclicker works just fine, but the only way to kill it is forcefully shut down my computer because it clicks so fast I can't access my taskbar. I could make it slower, but I'd prefer a way for the user to close the autoclicker with the press of a button. I've tried if keyboard.is_presssed('q'): break
but I always get the error message AttributeError: 'Controller' object has no attribute 'is_pressed'. Did you mean: 'alt_pressed'? I expected my code to break the loop when I press q, but instead I get an error message. The error message will also pop up without the pressing of q. My code as of now is:
from pynput.mouse import Button, Controller
from pynput.keyboard import Key, Controller
import time
keyboard = Controller()
mouse = Controller()
while True:
time.sleep(10)
mouse.click(Button.left)
if keyboard.is_pressed('q'):
break
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pynput
没有is_presse()
- 我不知道您在哪里找到它。您应该使用
pynput.keyboard.listener
在按下q
时运行代码结束程序。您不能有两个具有相同名称
控制器
的对象。一个
控制器
替换其他控制器
,然后您使用相同的Controller
来创建鼠标
键盘代码> - 这使问题问题。您必须使用
pynput.mouse.controller
和pynput.keyboard.pynput.controller
编辑:
在
q 您必须使用
侦听器
例如:
pynput
doesn't haveis_pressed()
- I don't know where you find it.You should rather use
pynput.keyboard.Listener
to run code whenq
is pressed and set some variable -q_is_pressed = True
- or run code which ends program.You can't have two objects with the same name
Controller
.One
Controller
replaces otherController
and later you use the sameController
to createmouse
andkeyboard
- and this makes problem.You have to use
pynput.mouse.Controller
andpynput.keyboard.pynput.Controller
EDIT:
To end code when
q
was pressed you have to useListener
For example: