def grab(self): # get the geometry of the window geometry = self.window.get_geometry() # convert coords to global display coords coords = Xrequest.TranslateCoords( display=self.display.display, src_wid=self.window, dst_wid=self.window.query_tree().root, src_x=0, src_y=0) monitor = { 'left': coords.x, 'top': coords.y, 'width': geometry.width, 'height': geometry.height } # take screenshot return np.array(self.screenshot.grab(monitor))
def translate_coords(self, src_window, src_x, src_y): return request.TranslateCoords(display=self.display, src_wid=src_window, dst_wid=self.id, src_x=src_x, src_y=src_y)
print("Select window in 3 seconds") time.sleep(3) window = display.get_input_focus().focus while True: with mss.mss() as screenshot: # start timing t1 = time.time() # get the geometry of the window geometry = window.get_geometry() # convert coords to global display coords coords = Xrequest.TranslateCoords(display=display.display, src_wid=window, dst_wid=window.query_tree().root, src_x=0, src_y=0) monitor = { 'left': coords.x, 'top': coords.y, 'width': geometry.width, 'height': geometry.height } # print time after converting coordinates t2 = time.time() print("Converted to screen coordinates in " + str(t2 - t1) + "s") # take screenshot image = screenshot.grab(monitor)