pyautogui.pixel(x,y) 在 while 循环中开始滞后 [英] pyautogui.pixel(x,y) starts lagging in a while loop

查看:91
本文介绍了pyautogui.pixel(x,y) 在 while 循环中开始滞后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查屏幕上的像素何时发生变化,然后在像素发生颜色变化时设置键盘事件.但是大约 2-4 分钟后,当 pyautogui.pixel() 被多次调用时,计算机会变慢.

I want to check when a pixel on the screen is changing and then put a keyboard event when the pixel is changing colors. But after about 2-4 min the computer slows down when pyautogui.pixel() have been called multiple times.

这是我的代码

import pyautogui

OldC1 = None

while True:
   NewC1 = pyautogui.pixel(750, 550)

   if NewC1 != OldC1:
      pyautogui.press('up')

   OldC1 = NewC1;

有没有办法绕过延迟?

推荐答案

我也遇到过类似的问题,我绕过这个问题的方法是直接使用 PIL 的函数,而不是 pyautogui 的包装函数:

I've encountered similar issues, my way of circumventing that problem was to use PIL's functions directly, instead of pyautogui's wrapper functions:

from PIL import ImageGrab

pixelRGB = ImageGrab.grab().getpixel((x, y))

使用此功能并没有降低我的电脑速度.

Using this function did not slow down my pc.

这篇关于pyautogui.pixel(x,y) 在 while 循环中开始滞后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆