whyeyes
whyeyes

Reputation: 31

Python MSS Screen Capture target specific windows

Is there any way to screencapture specific windows from windows handle? Even the windows is in the background it still will capture it. currently i only have this code for record the fullscreen desktop not in the specific windows.


def window_capture():
    # Define your Monitor
    x = 0
    y = 0
    w = 1920
    h = 1080
    
    hwnd = None

    with mss.mss() as sct:
        # Part of the screen to capture
        monitor = {"left": x, "top": y, "width": w, "height": h}
        img = sct.grab(monitor)
        img = np.array(img)
    return img



while "Screen capturing":
    # Define Time
    last_time = time()

    # Get the img
    screenshot = window_capture()

    # Display the picture
    cv.imshow('Computer Vision', screenshot)

    print(f'FPS {(1 / (time() - last_time))}')

    # Press "q" to quit
    if cv.waitKey(1) == ord("q"):
        cv.destroyAllWindows()
        break

Upvotes: 3

Views: 6320

Answers (1)

glorindel
glorindel

Reputation: 23

Hi I was searching for same answer as you, it looks like mss cant do that.

Possible way how to do that is with win32api.

Check this: Fastest way to take a screenshot with python on windows

Upvotes: 1

Related Questions