4
import pyautogui
import time

def test_time():
    t1 = time.time()
    for i in range(100):
        img = pyautogui.screenshot()
    t2 = time.time()
    print(t2-t1)
test_time()

I am trying to make bot, which checks pixels and then clicks at them, but screenshots taking too much time (14.93 sec for 100 screenshots) is there any faster ways to do it?

2 Answers2

1

Depending on the platform, you might be able to speed the call up by supplying a region keyword argument, such a the following:

im = pyautogui.screenshot(region=(20, 20, 80, 80))

On Linux, this region will be used in the underlying screenshot process (which could significantly speed up the process when only a smaller region is required), but on Windows and macOS this will not help.

You could look into more specific solutions with other libraries, including MSS, which you can read the documentation here. It has a simple API and is pretty fast.

xavc
  • 1,245
  • 1
  • 8
  • 14
-3

To take a screenshot on macOS press cmd+shift+4

kailashT
  • 1
  • 2