python-mss icon indicating copy to clipboard operation
python-mss copied to clipboard

Capture single window

Open stuaxo opened this issue 4 years ago • 7 comments

There should be options to capture single windows.

There is complication here, as different strategies may not work in even within a single OS.

IMO where possible capture should not capture the whole screen clipped to the window, where possible it should use native APIs to grab just the window.

On windows, one example of this is here https://stackoverflow.com/questions/19695214/python-screenshot-of-inactive-window-printwindow-win32gui

It doesn't work for Modern UI apps, (so calculator does not work, but notepad does), where different APIs are needed, but it's probably better than nothing / a start ?

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

stuaxo avatar Oct 19 '20 05:10 stuaxo

Not a dev here but here I have an idea on how this could be done.

  • On Linux, use an interface for X11
  • On Windows, use Win32GUI API
  • On Mac, could use appscript

Find the Window size and position with the API, and use that as the mask for the screen capture.

sagarreddypatil avatar Oct 22 '20 02:10 sagarreddypatil

This can definitely be done.

I'm arguing against a mask + fullscreen capture where possible so that windows don't need to be moved to the front to be captured.

stuaxo avatar Oct 22 '20 09:10 stuaxo

Is it possible to capture a single app window on OSX?

salonsoGH avatar Nov 06 '20 11:11 salonsoGH

Looks like it https://stackoverflow.com/a/48030215

stuaxo avatar Nov 06 '20 13:11 stuaxo

I meant, with this library using python.

salonsoGH avatar Nov 06 '20 13:11 salonsoGH

No, that is what this issue is to request.

There is another project called screenshot that you can use for that.

stuaxo avatar Nov 08 '20 19:11 stuaxo

Here's a Windows implementation of this feature from flexx (purely with ctypes): https://github.com/flexxui/flexx/blob/master/flexx/util/screenshot.py Though the comment says that it supports Linux, it seems that only the Windows part is implemented.

archiif avatar May 11 '21 13:05 archiif