I need to track pixels on my screen very fast, but win32gui.GetPixel() is failing when I right-click with my mouse a few times.
I managed to reproduce the same error right-clicking fast with the mouse anywhere on the screen while below code is running.
CODE:
import win32gui
for j in range(50):
for i in range(500):
wid = win32gui.GetDesktopWindow()
hdc = win32gui.GetWindowDC(wid)
colour = win32gui.GetPixel(hdc, 10, 10)
win32gui.ReleaseDC(wid, hdc)
print(j*500 + i, wid, hdc, colour)
ERROR:
Traceback (most recent call last):
File "<ipython-input-5-cf83afe48fec>", line 7, in <module>
colour = win32gui.GetPixel(hdc, 10, 10)
error: (0, 'GetPixel', 'No error message is available')
When I don't right-click, the code works perfectly giving me the pixel colour.
Using: Python 3.6.3 |Anaconda custom (64-bit)