我目前正在学习Python(大约3个月的经验),并想尝试模块“鼠标”,我构建了一个简单的autoclicker脚本(不使用它在游戏中),但对于高于12( cps )的值它达到目标cps以下,我怀疑这是因为我的程序中的if循环,谁能帮助我使这更有效率?
代码如下:
import mouse
import keyboard
import time
staat = 0
cps = input("Typ de hoeveelheid cps die je wilt in.")
cps = float(cps)
cps = 1 / cps
print("pauzeer de loop door op / te drukken")
while True:
if staat == 1:
mouse.click('left')
if keyboard.is_pressed('/'):
if staat == 0:
staat = 1
else:
staat = 0
time.sleep(cps)提前感谢
发布于 2021-09-24 20:38:25
使用1而不是True会稍微快一些。以这种方式导入会稍微快一些,而且调用时不会使用'.‘速度也稍快一些。如果仍然不够快,我可以实现多线程。
from mouse import click
from keyboard import is_pressed
from time import sleep,perf_counter
staat = 0
cps = input("Typ de hoeveelheid cps die je wilt in.")
cps = float(cps)
cps = 1 / cps
print("pauzeer de loop door op / te drukken")
while 1:
timeing = perf_counter()
if staat:
click('left')
if is_pressed('/'):
if not staat:
staat = 1
else:
staat = 0
sleep(cps - (perf_counter() - timeing)https://stackoverflow.com/questions/69320587
复制相似问题