Automated screenshot capture with process tracking and intelligent deduplication
QtRecon includes a sophisticated screenshot module that automatically captures screen content at intervals, with intelligent deduplication and process tracking capabilities.
if self.engine == 'qt': from PySide6.QtGui import QGuiApplication # If the number of screens (= screenshots) changed: if len(self.previous_screenshots) != len(QGuiApplication.screens()): self.previous_screenshots = [None] * len(QGuiApplication.screens()) for i, screen in enumerate(QGuiApplication.screens()): original_pixmap = screen.grabWindow(0) if not original_pixmap.save(f"{screenshot_filename_prefix}-{i}.png"): return False else: screenshot_files.append(f"{screenshot_filename_prefix}-{i}.png")
The Qt engine automatically handles multiple monitors, creating separate screenshots for each display.
else: if len(self.previous_screenshots) == 0: self.previous_screenshots = [None] # Let's consider there is only one screen subprocess.run([ chunk.replace('%%%OUTPUT%%%', f"{screenshot_filename_prefix}.png") for chunk in self.screenshot_cmd.split() ]) screenshot_files.append(f"{screenshot_filename_prefix}.png")
while True: try: progress.reset(master_task) progress.update(master_task, description="Screenshoting...") try: screenshot_mgr.take_screenshot() except Exception as e: progress.console.print(f"[red]Failed to save screenshot ![/red]") # Tempo for i in range(interval): time.sleep(1) progress.advance(master_task)
for i, current_screenshot in enumerate(current_screenshots): # If more than X pixels different from previous screenshots if current_screenshot and ( not self.previous_screenshots[i] or len(set(ImageChops.difference( current_screenshot, self.previous_screenshots[i] ).getdata())) > self.pixel_threshold_different_images ): self.nb_of_screenshots += 1 self.previous_screenshots[i] = current_screenshot
Screenshots are cropped (61 pixels from each edge) before comparison to ignore taskbars and window decorations that may change frequently.
def take_screenshot(self) -> bool: # Checking lockscreen: if self.check_locked_screen: cmd = subprocess.Popen( self.check_locked_screen_cmd.split(), stdout=subprocess.PIPE ) if any([self.check_locked_screen_cmd_result in line.decode() for line in cmd.stdout.readlines()]): return False
The lock screen detection command is platform-specific. The default configuration works on Linux systems using D-Bus and freedesktop.org standards.