1

while I was making a magic piano tiles bot using python, an error occurred, here is my code:

from pyautogui import *
import pyautogui
import keyboard
import win32api, win32con

#X:  850 Y:  226
#X:  563 Y:  702
#X:  651 Y:  704
#X:  866 Y:  729

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(850, 226)[0] == 0:
        click(850, 226)
    if pyautogui.pixel(563, 702)[0] == 0:
        click(563, 702)
    if pyautogui.pixel(651, 704)[0] == 0:
        click(651, 704)
    if pyautogui.pixel(866, 729)[0] == 0:
        click(866, 729)

here is my output:

Traceback (most recent call last):
  File "c:\Users\Ender_Bender\Desktop\projects\my stuff\image-bot\main.py", line 20, in <module>
    if pyautogui.pixel(850, 226)[0] == 0:
  File "C:\Users\Ender_Bender\AppData\Roaming\Python\Python39\site-packages\pyscreeze\__init__.py", line 613, in pixel
    return (r, g, b)
  File "C:\Program Files\Python39\lib\contextlib.py", line 124, in __exit__
    next(self.gen)
  File "C:\Users\Ender_Bender\AppData\Roaming\Python\Python39\site-packages\pyscreeze\__init__.py", line 122, in __win32_openDC
    raise WindowsError("windll.user32.ReleaseDC failed : return 0")
OSError: windll.user32.ReleaseDC failed : return 0

does anyone know why this is and how to fix it? thanks!

techy101
  • 47
  • 4
  • What Python version are you running? According to [this thread](https://stackoverflow.com/questions/59146513/pyautogui-and-pyscreeze-crash-with-windll-user32-releasedc-failed), you can try running in 3.7. Although this is an officially [known and reported issue](https://github.com/asweigart/pyautogui/issues/579) that's still open/unresolved. You didn't mention finding either of those pages so I'm not sure what research you've already done - I suggest including what you've researched so far so we don't just show you links that you've already looked at. – Random Davis Jun 18 '21 at 18:05

0 Answers0