我做了一个带杀戮开关的自动点击器。按“s”键后,程序停止。唯一的问题是,您必须按住“s”键,直到自动单击功能完成。在代码中,我将函数设置为运行0.5秒
如何使我的kill开关更有效?我希望程序在你按下键的那一刻停止
#! /usr/bin/python
import pyautogui
import time
import keyboard
# The Switch
on_off = True
print("Auto Clicker Started")
# This function does the clicking
def Auto_Click():
width, height = pyautogui.position()
pyautogui.click(width, height)
time.sleep(0.5)
# Checks if you hit the kill button. If you did not hit the kill button, run the Auto_Click function.
while on_off == True:
if keyboard.is_pressed('s') == True:
on_off = False
print("Auto Clicker Killed")
Auto_Click()
您可以使用线程来实现这一点。通过创建一个单独的线程来检查“s”键,它可以与自动点击器一起运行。这意味着按键时没有延迟
编辑-添加简历按钮
我已将“r”键绑定到resume,并更改了程序的工作方式以允许这种情况发生。现在有一个无限循环试图启动自动单击器,因此当单击器停止时,程序不会停止。然后在
check_press
内on_off
的值根据按下的键进行设置。当on_off
设置为True时,在另一个线程中运行的无限循环将启动autoclicker循环相关问题 更多 >
编程相关推荐