1

I am trying to capture the pixels of a game to script a bot. I have a simple function:

def printPixel():
  while True:
    flags, hcursor, (x,y) = win32gui.GetCursorInfo()
    print x,y,':',ImageGrab.grab().getpixel((x,y))

This prints the current x,y coords and the RGB value of that pixel. This works as expected on my desktop hovering over various icons and such, but the same function does not work in-game. Any thoughts?

edit: When I save the image to a file and perform this same operation on the saved image, it works perfectly in-game. However, it is way slower. I'd like to operate on the image in memory, and not from a file.

jacobra
  • 2,102
  • 2
  • 14
  • 20

1 Answers1

1

Video games often deal with th graphical system directly for performance reasons, so some of the typical windows apis might not work on them. Try and take a screenshot by pressing the print screen button. If that captures your screen than you can take a screenshot in python and check the image you have captured taking into account the cursor position.

To take a screenshot on windows you can check out this answer to the question Fastest way to take a screenshot with python on windows it uses the win32gui library as you are using.

Community
  • 1
  • 1
Marwan Alsabbagh
  • 25,364
  • 9
  • 55
  • 65