Screen clipping

Post your working scripts, libraries and tools
User avatar
Joe Glines
Posts: 542
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: Screen clipping

08 Dec 2017, 20:04

@rommmcek Thank you for working on this! What I don't understand is why I don't have similar issues. I have four monitors and all are at different resolutions. Any thoughts on why I don't have the same issue as Tank? Perhaps his graphics cards/drivers are the issue?
rommmcek
Posts: 355
Joined: 15 Aug 2014, 15:18

Re: Screen clipping

09 Dec 2017, 02:03

I'm actually working on correct capturing under MS Magnifier. Currently I'm able to do this if the upper left corner of the screen has 0, 0 coordinate values at 100%, 200%, 300%, ... magnification.
What I do is in fact displacing of the capturing point, calculated by ScreenClipping. This should work for every one.

I certainly don't know what causes Tank's problem, I made just a supposition it could be related to resolution difference (since resolution is "artificially" increased by magnifier), but of course I don't know what is the ratio between his values.

So if somebody experiences capturing down and left (Tank's report) of the GUI, he should increase x and decrease y values at the reported spot of the Gdip_BitmapFromScreen(Screen=0, Raster="") function and apply this only on the problematic monitor.

bye!
User avatar
Sabestian Caine
Posts: 248
Joined: 12 Apr 2015, 03:53

Re: Screen clipping

13 Dec 2017, 12:07

rommmcek wrote:Just play with these two lines:
- v1:=237, v2:=207 (where to show)
- x:=237, y:=207, w:=683, h:=400 (what to capture)
P.s.: Please remove this: sx:=sx*2, sy:=sy*2 (just this, curly bracket remains!). This was blunder of mine!


thank u so much dear rommmcek...now i am able to clip the desired part of screen and i am also able to put it at the desired location on the screen also....
but there is one more problem-
as when i press f1 key then it shows the desired clip at desired location, which is ok..... for this my codes are these-

Code: [Select all] [Download] GeSHi © Codebox Plus

f1::
SCW_ScreenClip2Win(clip:=1,email:=0,IMUGR:=0)
return
#include C:\My Documents\Scripts\ScreenClipping_block.ahk

but i want that when i press f3 key then it should clip some other part of screen, at some other location on screen. I tried to use these codes-

Code: [Select all] [Download] GeSHi © Codebox Plus

f1::
SCW_ScreenClip2Win(clip:=1,email:=0,IMUGR:=0)
return

f3::
SCW_ScreenClip2Win(clip:=1,email:=0,IMUGR:=0)
return

#include C:\My Documents\Scripts\ScreenClipping_block.ahk




but, If i change "what to capture" and "where to show" coordinates in screenclipping_block.ahk script for f3 they, then it changes the desired clip and desired location of clip which was set by f1 key also. In other words f1 key and f3 key work same in the above codes. So please tell me how can i use SCW_ScreenClip2Win fucntion in screenclipping_block.ahk script for two or more than two keys for showing two different rectangles (images) of screen at two different parts (region) of screen? please help... thanks a lot...
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
rommmcek
Posts: 355
Joined: 15 Aug 2014, 15:18

Re: Screen clipping

13 Dec 2017, 18:46

Below global IMUGR_client:="XXXXX" put:

Code: [Select all] [Download] GeSHi © Codebox Plus

global f1wtsv1, f1wtsv2, f1wtcx, f1wtcy, f1wtcw, f1wtch
global f2wtsv1, f2wtsv2, f2wtcx, f2wtcy, f2wtcw, f2wtch
global f3wtsv1, f3wtsv2, f3wtcx, f3wtcy, f3wtcw, f3wtch
HotKeys:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Where to show:

Code: [Select all] [Download] GeSHi © Codebox Plus

if (A_ThisHotkey = "f1")
v1:=f1wtsv1, v2:=f1wtsv2
else if (A_ThisHotkey = "f2")
v1:=f2wtsv1, v2:=f2wtsv2
else if (A_ThisHotkey = "f3")
v1:=f3wtsv1, v2:=f3wtsv2
What to clip:

Code: [Select all] [Download] GeSHi © Codebox Plus

if (A_ThisHotkey = "f1")
x:=f1wtcx, y:=f1wtcy, w:=f1wtcw, h:=f1wtch
else if (A_ThisHotkey = "f2")
x:=f2wtcx, y:=f2wtcy, w:=f2wtcw, h:=f2wtch
else if (A_ThisHotkey = "f3")
x:=f3wtcx, y:=f3wtcy, w:=f3wtcw, h:=f3wtch
Last edited by rommmcek on 17 Dec 2017, 01:20, edited 2 times in total.
User avatar
Sabestian Caine
Posts: 248
Joined: 12 Apr 2015, 03:53

Re: Screen clipping

14 Dec 2017, 12:39

rommmcek wrote:Below global IMUGR_client:="XXXXX" put:

Code: [Select all] [Download] GeSHi © Codebox Plus

global ClipWidth, ClipHight
HotKeys:

Code: [Select all] [Download] GeSHi © Codebox Plus

f1::
f2::
f3::SCW_ScreenClip2Win(clip:=1,email:=0,IMUGR:=0)
Where to show:

Code: [Select all] [Download] GeSHi © Codebox Plus

f (A_ThisHotkey = "f1")
v1:=0, v2:=0 ; upper left corner
else if (A_ThisHotkey = "f2")
v1:=A_ScreenWidth-ClipWidth, v2:=0 ; upper right corner
else if (A_ThisHotkey = "f3")
v1:=0, v2:=A_ScreenHeight-ClipHight ; lower left corner
What to clip:

Code: [Select all] [Download] GeSHi © Codebox Plus

if (A_ThisHotkey = "f1")
x:=300, y:=200, w:=ClipWidth:=100, h:=ClipHight:=50
else if (A_ThisHotkey = "f2")
x:=500, y:=400, w:=ClipWidth:=150, h:=ClipHight:=75
else if (A_ThisHotkey = "f3")
x:=700, y:=600, w:=ClipWidth:=200, h:=ClipHight:=100



Thank you very much dear rommmcek.... this is really what i wanted..... you are really great...

sir one more thing i want to know just for knowledge purpose-
can't we add "what to clip" and "where to show" coordinates within the function itself for better compatibility.
please see below a fictitious example-

Code: [Select all] [Download] GeSHi © Codebox Plus

f1::
SCW_ScreenClip2Win( x:=237, y:=207, w:=683, h:=400, v1:=237, v2:=207)
return

f2::
SCW_ScreenClip2Win( x:=244, y:=214, w:=6847, h:=350, v1:=145, v2:=652)
return

#include C:\My Documents\Scripts\ScreenClipping_block.ahk


if the above can happen then it would be very easy to use the script. Please guide.... thanks a lot...
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
rommmcek
Posts: 355
Joined: 15 Aug 2014, 15:18

Re: Screen clipping

15 Dec 2017, 16:19

I've updated post above, just custom edit variables in Hotkey(s). (see post below)
P.s.: Now the native #Lbutton Hotkey is preserved.
rommmcek
Posts: 355
Joined: 15 Aug 2014, 15:18

Re: Screen clipping

17 Dec 2017, 01:31

New update!
Script will work as original! Besides you can optionally define e.g. f1 where to clip & where to show via ^f1 & !f1
Example for f1:
1. Hold down Win and drag with mouse desired clip.
2. Press ^f1 to define where to clip
3. Move the ScreenClippingWindow with mouse to the desired position and press !f1 to define where to show
4. Press Esc to destroy ScreenClippingWindow
5. Press f1 to clip (desired portion) and show it at desired positon

P.s: To save time download attachment (6)
Attachments
ScreenClipping_block.zip
(21.5 KiB) Downloaded 68 times
burque505
Posts: 492
Joined: 22 Jan 2017, 19:37

Re: Screen clipping

17 Dec 2017, 14:56

I've been using Joe Glines's script for quite a while now, rommmcek's updates are cool. Thanks a million, you guys! :clap:

In the spoiler is my little tweak with the ability to pick a folder to save in. (I don't like the default folder select dialog, and I know there's an updated version somewhere that I remember fiddling with in a VB script a year or so ago, but I can't find it now. Arrrgh...)

1) Edit line 4 to suit (global folderVar := "C:\Users\" . A_UserName . "\Desktop\AHK\ClipShots\"). This is the default save folder.
2) Edit line 86 to suit (^#s::FileSelectFolder, folderVar, *C:\Users\%A_UserName%\Desktop\AHK\ClipShots\,3).
3) Change lines 46,47, and 48 to suit your clipping, emailing and IMGUR preferences. You probably won't want to use mine.

A) Ctrl+Shift+S saves to the folder in 'folderVar'.
B) Ctrl+Win+S brings up the folder select dialog for the 'save' folder.
C) Ctrl+Win+Q displays a message box with the current save folder.

Spoiler


Thanks again, guys.
Regards,
burque505
goji
Posts: 2
Joined: 23 Mar 2017, 09:12

Re: Screen clipping

12 Jan 2018, 18:49

This is amazing and works well on the installed AHK version. However it doesn't with the portable one. Which is unfortunately what i use.. And what i wish to keep using. I can see the drag area showing up, but in the end, no file saved, no windows, etc.. Just not working. I'd like to understand why : am i missing something or it just can work on a portable version? Let me know, thanks :)

PS: I'd also like to remove the outlook part.. ^^
User avatar
kczx3
Posts: 578
Joined: 06 Oct 2015, 21:39

Re: Screen clipping

25 Mar 2018, 15:02

I am trying to get better at working with classes in AHK. So I took a stab at converting this to a class. I wanted to figure out how to use a Resize handler on the screen shot GUIs to adjust the border to the size but don't have that much experience with GDI+. Also, it doesn't seem that there is a good way in AHK v1.1 to use a class method as a GUI OnSize handler. Criticism is welcome for learning.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

SanyaIV
Posts: 4
Joined: 22 Apr 2018, 06:26

Re: Screen clipping

22 Apr 2018, 06:32

Lately I've been having issues with this script. Basically sometimes it doesn't copy the data into the clipboard. Example: I do a screenshot using WinKey + LeftMouse, paste it into Paint (just to check clipboard content) and it's fine, I take another one and paste, and it's not the new one but the old one, I take yet another one and paste, now it says no data that paint can use, and take yet another one after that and it'll work again. This happens ~50% of the time and I don't know why. It also happens with the one rommmcek uploaded. I don't really know anything about AHK scripting, I just know that I absolutely love this script, or at least used to when it worked reliably. Does anyone happen to know how to fix this?
User avatar
kczx3
Posts: 578
Joined: 06 Oct 2015, 21:39

Re: Screen clipping

22 Apr 2018, 07:03

Does mine do the same?
burque505
Posts: 492
Joined: 22 Jan 2017, 19:37

Re: Screen clipping

22 Apr 2018, 16:08

SanyaIV, I had some similar (if not related) issues, not with these screen clipping scripts, but with pasting in general. They are gone, thank goodness, after rebooting and running CCleaner.

It appears that, at least for my system (Win7 64-bit), the Office 2016 clipboard was interfering with pasting into RichEdit fields in other applications (those that use msftedit.dll), and also with copying from those applicatons.

Occasionally I could even see the desired image being pasted just for milliseconds, then the old image would be pasted instead. It also corrupted some RTF documents, adding "ghost" images that would not display. This happened with Wordpad, LibreOffice Writer, and Word.

Might it be possible you have some Office application running when this behavior occurs?

Regards,
burque505
SanyaIV
Posts: 4
Joined: 22 Apr 2018, 06:26

Re: Screen clipping

24 Apr 2018, 01:45

kczx3 wrote:Does mine do the same?


Just tried it and I don't think I understand how to use it, it doesn't seem to copy the contents of the screenshot into clipboard.

burque505 wrote:SanyaIV, I had some similar (if not related) issues, not with these screen clipping scripts, but with pasting in general. They are gone, thank goodness, after rebooting and running CCleaner.

It appears that, at least for my system (Win7 64-bit), the Office 2016 clipboard was interfering with pasting into RichEdit fields in other applications (those that use msftedit.dll), and also with copying from those applicatons.

Occasionally I could even see the desired image being pasted just for milliseconds, then the old image would be pasted instead. It also corrupted some RTF documents, adding "ghost" images that would not display. This happened with Wordpad, LibreOffice Writer, and Word.

Might it be possible you have some Office application running when this behavior occurs?

Regards,
burque505


No Office applications running that I know of.
User avatar
kczx3
Posts: 578
Joined: 06 Oct 2015, 21:39

Re: Screen clipping

24 Apr 2018, 09:53

Guess I hadn't incorporated that functionality yet. Sorry.
rommmcek
Posts: 355
Joined: 15 Aug 2014, 15:18

Re: Screen clipping

24 Apr 2018, 21:35

Looks like you're having problems outside the ScreenClipping tool.
As a workaround try replacing Send, !{PrintScreen} ; Active Win's client area to Clipboard with:

Code: [Select all] [Download] GeSHi © Codebox Plus

   Clipboard:=""
loop, 4 { ;increase number of loops to ensure better realiability (e.g. under CPU load)
;SoundBeep, 8000 ; uncomment this line to determine number of loops needed (high pitched beep)
Send, !{PrintScreen} ; Active Win's client area to Clipboard
ClipWait, .3, 1 ; increase ".3" for slow computers
if !ErrorLevel
break
}
SanyaIV
Posts: 4
Joined: 22 Apr 2018, 06:26

Re: Screen clipping

03 May 2018, 03:03

rommmcek wrote:Looks like you're having problems outside the ScreenClipping tool.
As a workaround try replacing Send, !{PrintScreen} ; Active Win's client area to Clipboard with:

Code: [Select all] [Download] GeSHi © Codebox Plus

   Clipboard:=""
loop, 4 { ;increase number of loops to ensure better realiability (e.g. under CPU load)
;SoundBeep, 8000 ; uncomment this line to determine number of loops needed (high pitched beep)
Send, !{PrintScreen} ; Active Win's client area to Clipboard
ClipWait, .3, 1 ; increase ".3" for slow computers
if !ErrorLevel
break
}


Been trying it for a while but seems it didn't fix it. =/ Still a lottery if the screenshot gets added to clipboard.
rommmcek
Posts: 355
Joined: 15 Aug 2014, 15:18

Re: Screen clipping

03 May 2018, 23:47

This is pretty discouraging. You should proceed like this:

1. Manually
- close (if possible all) running Apps on your computer (fresh restarted computer would be still better)
- run explorer
- run clipbrd (or any other similar App to monitor clipboard content) and resize it to less then half screen width/hight
- activate explorer and resize it so you can see the Viewer at the same time
- hit Alt+PrintScreen and monitor the Viewer
- repeat a few times with different programs in place of explorer

2. Programatically
- still running Viewer and explorer (other apps closed as much as possible)
- run TestCopyWin.ahk
- activate resized explorer
- hit Ctrl+i and monitor the Viewer
- repeat a few times with different programs in place of explorer

3. ScreenClipping
- still running Viewer and explorer (other apps closed as much as possible)
- run ScreenClipping and test it while monitoring Viewer

4. Report results
Attachments
TestAndView.zip
(46.75 KiB) Downloaded 17 times
SanyaIV
Posts: 4
Joined: 22 Apr 2018, 06:26

Re: Screen clipping

06 May 2018, 10:19

rommmcek wrote:This is pretty discouraging. You should proceed like this:

1. Manually
- close (if possible all) running Apps on your computer (fresh restarted computer would be still better)
- run explorer
- run clipbrd (or any other similar App to monitor clipboard content) and resize it to less then half screen width/hight
- activate explorer and resize it so you can see the Viewer at the same time
- hit Alt+PrintScreen and monitor the Viewer
- repeat a few times with different programs in place of explorer

2. Programatically
- still running Viewer and explorer (other apps closed as much as possible)
- run TestCopyWin.ahk
- activate resized explorer
- hit Ctrl+i and monitor the Viewer
- repeat a few times with different programs in place of explorer

3. ScreenClipping
- still running Viewer and explorer (other apps closed as much as possible)
- run ScreenClipping and test it while monitoring Viewer

4. Report results


All of them worked correctly, except the application clipbrd which at certain times would bug out and stop updating until relaunching it. Really not sure here, it seems like it's working correctly now. For the sake of it I just launched the pre-edit one and it almost instantly stopped updating the clipboard. The post-edit one seems to be holding up now but at the same time there was that time earlier when it didn't update clipboard, I'm guessing my system is just either unstable or some other application is messing with things. Either way, post-edit is holding up well enough for everyday use at least, I'm satisfied with this.

Edit: :facepalm: So I thought I had a shortcut set up in my startup folder but turns out it was the actual old file, so whenever I restarted I would get the pre-edit version rather than the post-edit, that would explain things. In other words, the post-edit version most likely works 100%!
Stamimail
Posts: 60
Joined: 06 Nov 2014, 08:48

Re: Screen clipping

31 May 2018, 00:59

@Joe Glines
I suggest to change the
Rbutton:: winclose, A
to middle button (close the window like a middle click on a tab).
Use RightClick for ContextMenu with options.
Sorry I don't know how to implement this myself (still a newbie).

Is there someone can solve the problem of the incompatibility between the yellow selection range and the cursor position? To be able to use it, no matter what the DPI is?

Return to “Scripts and Functions”

Who is online

Users browsing this forum: DuyMinh and 20 guests