我怎样才能使这个脚本更有效率?(Python)

How can i make this script more efficient?(Python)

我目前正在学习 Python(现在大约有 3 个月的经验)并想尝试模块“鼠标”,我构建了一个简单的自动点击器脚本(不在游戏中使用它)但是对于 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)

提前致谢

使用 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)