bencevans / screenshot-desktop

💻 Capture a screenshot of your local machine
https://www.npmjs.com/package/screenshot-desktop
437 stars 91 forks source link

Screenshot Specific Window #121

Open seiyria opened 5 years ago

seiyria commented 5 years ago

I would like to use a handler to grab a particular window and screenshot that. it doesn't seem to be possible yet, but is this something that can be easily supported?

bencevans commented 5 years ago

This can be supported, methods to do so would need to be investigated for each operating system. I don't have any need individual windows myself, thus won't be developing the feature however very open to a pull request adding support!

bencevans commented 5 years ago

For Windows there's a function already existing in the .bat script used.

https://github.com/bencevans/screenshot-desktop/blob/1f1beaa689875815f686c93e10314280fd0d1f07/lib/win32/screenCapture_1.3.2.bat#L71-L82

I propose that be used with an interface along the lines of:

const windows = await screenshot.listWindows()
const firstWindowImage = await screenshot({ windowId: windows[0].id })
const minecraftImage = await screenshot({ windowTitle: 'Minecraft' })
seiyria commented 5 years ago

I think your interface makes sense. My concern with the windowTitle example is - what if you have multiple windows? I think it would make sense to return an array of images in this case, and get them all.

I implemented this using C#/edge here: https://github.com/seiyria/rectshot and in my module my solution was to iterate over the windows and take pictures of each of them.

bencevans commented 5 years ago

This is true, another alternative would be to only accept ids and not titles so a user must come up with their own logic if they wanted title targetting.

seiyria commented 5 years ago

I'm not sure that's a good idea. The average dev will not know how to get window ids nor should they be expected to be. Unless ListWindows will return something that allows for filtering, I would just make screenshot always return an array.

dovk commented 5 years ago

Perhaps this might interest someone: I wanted to narrow the image down to the specific area where the user was typing at the time, not the entire window. Since I am running under Electron I run an AHK script via Electron's child_process to get the caret position (this is not always available - in that case I use the mouse position via Electron's getCursorScreenPoint()) and I then use jimp to crop the screenshot-desktop image to an even square from the caret/mouse position for about 15% of the screen size in each direction. In my case I then pass the cropped (and grey-scaled) image to Tesseract-OCR and the results are excellent.

ppoliani commented 4 years ago

Hi guys,

Has there been any progress with this feature?

bencevans commented 4 years ago

Can't say I've delved into it at all but a PR adding the functionality would be very welcome!

On Wed, 5 Aug 2020, 10:58 Pavlos Polianidis, notifications@github.com wrote:

Hi guys,

Has there been any progress with this feature?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bencevans/screenshot-desktop/issues/121#issuecomment-669101640, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE34RZ4Z3POZ3RJJVPOVA3R7EUNPANCNFSM4GSOUX2Q .