0

I am trying to make a process recording program that I can view either on the same monitor or another with just dragging the "Screen Capture" window. Starting with just printing screen to GUI first:

So for this example, let's say I'm aiming for "Command Prompt." I input it as is, but when I run the program, the "Screen Capture" window will show everything on screen, not the specified program I want. How might I record just the specified window, not the entire screen?

import cv2
import numpy as np
import pygetwindow as pgw
import pyautogui as pag

process_window_name = 'Command Prompt'

def main():
    while True:
        process_window = None
        for window in pgw.getAllTitles():
            if process_window_name in window:
                process_window = pgw.getWindowsWithTitle(window)[0]
                break

        if process_window is not None:
            left, top, width, height = process_window.left, process_window.top, process_window.width, process_window.height

            screen = pag.screenshot(region=(left, top, width, height))
            frame = np.array(screen)

            cv2.imshow('Window Capture', frame)

        if cv2.waitKey(1) == ord('q'):
            break

    cv2.destroyAllWindows()

if __name__ == "__main__":
    main()

What I tried to do was importing win32gui and tinkering with that, and I focused on one window with bring_window_to_front(), which did work if I just want to focus on that window for the entire time, but exiting that window causes multiple errors and it limits how I wish for the program to be.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.