title: Python error : OSError: windll.gdi32.GetPixel failed : return -1
body: <p>When I try to run a Python script, it works fine for about 10 minutes and it just stops. Also, I'm using Python 3.7.8. This is my code:</p>
  <pre><code>from pyautogui import *
  import pyautogui
  import time
  import keyboard
  import random
  import win32api, win32con
  
  def click(x,y):
      win32api.SetCursorPos((x,y))
      win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
      win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
  
  while keyboard.is_pressed('q') == False:
  
      if pyautogui.pixel(193, 52)[0] == 255:
          print(&quot;!&quot;)
          click(798, 386)
          time.sleep(1)
  </code></pre>
  <p>And this is the error that appears in the console:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\Administrator\Desktop\meh\FixedAuto.py&quot;, line 15, in &lt;module&gt;
      if pyautogui.pixel(193, 52)[0] == 255:
    File &quot;C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pyscreeze\__init__.py&quot;, line 609, in pixel
      raise WindowsError(&quot;windll.gdi32.GetPixel failed : return {}&quot;.format(color))
  OSError: windll.gdi32.GetPixel failed : return -1
  </code></pre>