1

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)

Hugo
  • 147
  • 1
  • 7
  • I can't replicate your issue on Win10. Do you need to get the desktop window every iteration. – import random Feb 12 '18 at 09:44
  • @Eric, no I don't, but won't avoid the error. Problem is only with right-click, left-click doesn't affect anything. – Hugo Feb 12 '18 at 20:30

0 Answers0