如何使Python结束一个循环,然后按键的按下键,然后在循环中不断按下左键单击并右键单击?

发布于 2025-02-11 08:13:24 字数 350 浏览 1 评论 0原文

我对Python和编码相对较新。我创建了一个脚本来帮助我执行重复任务。我的脚本很好,除了我从字面上找不到杀死它的方法。我的脚本不断按下左右鼠标按钮,我希望解决方案在另一个选项卡中放出时杀死它。我已经尝试了如果键盘。IS_PREDSER('e')break,并使用pynput并使用正确的代码(我真的无法在此网站上很好地弄清楚格式代码)。我可以使用什么解决方案?到目前为止,我的脚本是:

while True:
    mouse.click(Button.right)
    enter code here
    time.sleep(0.90)
    mouse.click(Button.left)

I am relatively new to python and coding in general. I've created a script to help me perform a repetitive task. My script is perfectly fine, except the part where I literally can't find a way to kill it. My script constantly presses the left and right mouse buttons and I would like a solution to kill it while tabbed out in another tab. I've tried if keyboard.is_pressed('e') break with importing pynput and using the right code (I couldn't really figure out format code well on this website). What solutions can I use? My script as of now is:

while True:
    mouse.click(Button.right)
    enter code here
    time.sleep(0.90)
    mouse.click(Button.left)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风渺 2025-02-18 08:13:24

按下键时,断路语句将触发,while循环将终止。如果不按下键,将重复序列。

while true:
    mouse.click(Button.right)
    # enter code here
    time.sleep(0.90)
    mouse.click(Button.left)
    def on_press(key):
    break

with Listener(
    on_press=on_press,
    on_release=on_release) as listener:
    listener.join()

When the key is pressed the break statement will trigger and the while loop will terminate. If the key is not pressed the sequence will be repeated.

while true:
    mouse.click(Button.right)
    # enter code here
    time.sleep(0.90)
    mouse.click(Button.left)
    def on_press(key):
    break

with Listener(
    on_press=on_press,
    on_release=on_release) as listener:
    listener.join()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文