我有一个简单的程序,它执行以下操作:1)用户将鼠标指向某处,2)然后用户按空格键,3)计算机在该点执行一定数量的左键鼠标单击。
该程序运行良好,只有一个问题 - 它在 4 核处理器上占用了 30-50% 的处理器时间。哪里有问题?
import pyautogui
import ctypes
pyautogui.FAILSAFE = True
def get_space_state():
hllDll = ctypes.WinDLL ("User32.dll")
VK_SPACE = 0x20
return hllDll.GetKeyState(VK_SPACE)
while True:
if get_space_state() == -127 or get_space_state() == -128:
print ("yes")
pyautogui.click(clicks=40 , interval=0.01)
非常感谢。