Screen clipping

Post your working scripts, libraries and tools for AHK v1.1 and older
medp7060nz
Posts: 3
Joined: 13 Mar 2022, 04:00

Re: Screen clipping

Post by medp7060nz » 13 Mar 2022, 04:11

Avastgard wrote:
01 Mar 2022, 10:03
However, I am facing a problem that every now and then the script will simply stop working and I have to reload it to get it working again. I get no error message and the script shows running in the system tray normally - it will simply stop snipping the screen for no apparent reason.
I have experienced this same problem just recently. It worked before without any issues. It looked like AutoHotkey v1.1.33.10 does not run properly with probably recent Windows updates in 2022. It will not recognize the Ctrl, Shift, Alt, Win keys once it stopped working for no known reasons. A restart of the script only works for a while.
rommmcek wrote:
03 Mar 2022, 00:56
That would trigger Duplicate hotkey error. Of course you could use:

Code: Select all

#Lbutton::
    SCW_SetUp()
    SCW_ScreenClip2Win(clip:=1,email:=0,OCR:=0)  ; Win+left click mouse=auto copy to clipboard
Return
instead, but I'm not sure how it would behave, since I didn't study the code entirely. It was just the idea to see if it would help you.
This does not resolve the issue.

Once it stopped working, no hotkeys defined in the script will work, so this also failed to wake it up:

Code: Select all

^F12:: SCW_SetUp()
The only solution is to "Reload This Script" !

The issue: why hotkeys (#^Lbutton::, #!Lbutton::, or #Lbutton::), which trigger the SCW_ScreenClip2Win(), became invalid after a while !!!!

Avastgard
Posts: 133
Joined: 30 Sep 2016, 21:54

Re: Screen clipping

Post by Avastgard » 13 Mar 2022, 19:41

medp7060nz wrote:
13 Mar 2022, 04:11
Avastgard wrote:
01 Mar 2022, 10:03
However, I am facing a problem that every now and then the script will simply stop working and I have to reload it to get it working again. I get no error message and the script shows running in the system tray normally - it will simply stop snipping the screen for no apparent reason.
I have experienced this same problem just recently. It worked before without any issues. It looked like AutoHotkey v1.1.33.10 does not run properly with probably recent Windows updates in 2022. It will not recognize the Ctrl, Shift, Alt, Win keys once it stopped working for no known reasons. A restart of the script only works for a while.
rommmcek wrote:
03 Mar 2022, 00:56
That would trigger Duplicate hotkey error. Of course you could use:

Code: Select all

#Lbutton::
    SCW_SetUp()
    SCW_ScreenClip2Win(clip:=1,email:=0,OCR:=0)  ; Win+left click mouse=auto copy to clipboard
Return
instead, but I'm not sure how it would behave, since I didn't study the code entirely. It was just the idea to see if it would help you.
This does not resolve the issue.

Once it stopped working, no hotkeys defined in the script will work, so this also failed to wake it up:

Code: Select all

^F12:: SCW_SetUp()
The only solution is to "Reload This Script" !

The issue: why hotkeys (#^Lbutton::, #!Lbutton::, or #Lbutton::), which trigger the SCW_ScreenClip2Win(), became invalid after a while !!!!
Yep, can confirm this. What I mentioned in my previous post did not work and I still have to reload the script manually.

Perhaps you could write a separate script that would reload this one every time you pressed #LButton, but that would make it impossible to have more than one clip at a time, since on every script reload the existing screen clips are closed.

medp7060nz
Posts: 3
Joined: 13 Mar 2022, 04:00

Re: Screen clipping

Post by medp7060nz » 14 Mar 2022, 00:03

It is possible that the problem is with AutoHotkey (v1.1.33.10) itself, rather than this script given similar issues have been reported before for many times. Modifier keys Ctrl, Shift, Alt, Win becoming stuck is a known issue with AutoHotkey for many reasons. Since a restart of the script is required, I guess it is a memory leaking issue, which is caused either by AutoHotkey or other programs running at the same time.

heldheldheld
Posts: 5
Joined: 27 Jan 2022, 14:44

Re: Screen clipping

Post by heldheldheld » 12 May 2022, 05:49

Would it be possible to add a rotation feature to rotate a screen clipping?

Gewerd_Strauss
Posts: 24
Joined: 12 Nov 2020, 02:34

Re: Screen clipping

Post by Gewerd_Strauss » 08 Jun 2022, 07:57

I have tried to get this script converted to an executable for a few friends which are unhappy about the default snipping tool. However, if I convert it, it simply does not work. Selecting an area does not create a window of that image part.
Furthermore, no image is pushed to the clipboard - However, according to the KeypressOSD, _something_ happens on the clipboard, as I get the "Clipboard Changed"-notification from it.

Is this issue only restricted to me?

User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Screen clipping

Post by BGM » 21 Jun 2022, 10:39

Eeewww, could be any number of nothings that is the problem. Maybe add your executable to your antivir whitelist.
Another thing, the script might or might not be unicode - so to compile it to exe you need to use the right ahk compilation mode (I think).
And this script requires some external libraries - depends on which version of this script that you have - and those libraries need to be up to date, too.

For example, I have been running this for a long time, but at some point the OCR functionality stopped working. I've been too lazy to figure out why, so I've let it go. But I'm sure it has to do with Win10's weirdness - which is the other one of the many nothings that are actual funstoppers.

User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Screen clipping

Post by BGM » 13 Oct 2022, 14:25

Revisiting... The script works for everything except the OCR part. The function is called fine, but the ocr function returns blank for the text. I've not figure it out. I'm currently running AutoHotkey 1.1.34.03 Unicode 32-bit on Windows 10.0.18363, if that might matter.

anhnha
Posts: 116
Joined: 08 Aug 2018, 02:46

Re: Screen clipping

Post by anhnha » 21 Dec 2022, 15:48

I understand this is difficult but have anyone tried or successed adding the functionality to edit the screenshot like inserting arrows or text or highlighting an area inside the screenshot?

anhnha
Posts: 116
Joined: 08 Aug 2018, 02:46

Re: Screen clipping

Post by anhnha » 22 Dec 2022, 02:28

rommmcek wrote:
07 Dec 2017, 09:30
@Tank: Sounds like you have different resolution on second monitor or probably vertical orientation (portrait).
Solution would be to scale the coordinates for capturing, adding x*=round(x*secondMonWidth/firstMonWidth), y*=round(y*secondMonHight/firstMonHight) before penultimate block/paragraph of the function: Gdip_BitmapFromScreen(Screen=0, Raster="")If my supposition is right, this would cause then capture image up to the right on first monitor! (or analogous, I might have mixed up scaling factors).
If so, next step would be automate scaling.
I have different resolution and also vertical orientation on my second monitor.
I still don't know where exactly I should add that line of code?

User avatar
rommmcek
Posts: 1474
Joined: 15 Aug 2014, 15:18

Re: Screen clipping

Post by rommmcek » 22 Dec 2022, 14:54

A few posts below is edited function.

P.s.: It's been a while since then, so odds the edited function will work for you, as it is, are slim, besides you don't describe your problem at all (didn't read posts beforehand).

anhnha
Posts: 116
Joined: 08 Aug 2018, 02:46

Re: Screen clipping

Post by anhnha » 23 Dec 2022, 18:20

Thanks, this is my monitors' information:
First monitor: 4K UHD 3840 x 2160 with zoom scale of 150%.
Second monitor: 1920 x 1080(FHD) ScreenRotate 90-degree Pivot mode with no scale.
The program works fine on the first monitor but the rectangle offset is off on the second monitor.
I'll try your solution when I get to the PC.

User avatar
rommmcek
Posts: 1474
Joined: 15 Aug 2014, 15:18

Re: Screen clipping

Post by rommmcek » 23 Dec 2022, 18:36

anhnha wrote:
23 Dec 2022, 18:20
... but the rectangle offset is off on the second monitor.
Off how much and in which direction?

anhnha
Posts: 116
Joined: 08 Aug 2018, 02:46

Re: Screen clipping

Post by anhnha » 23 Dec 2022, 19:32

Off how much and in which direction?
I don't have that PC here so I can't check it now but if I select a region in the middle of the second monitor, it would capture the region in the bottom instead.
So it is offset vertically quite large.

anhnha
Posts: 116
Joined: 08 Aug 2018, 02:46

Re: Screen clipping

Post by anhnha » 26 Dec 2022, 07:38

I added this line but now the capture regions become all black.

Code: Select all

 x*=round(x*1920/3840), y*=round(y*1080/2160)  ; <<<<<< This is the line added

anhnha
Posts: 116
Joined: 08 Aug 2018, 02:46

Re: Screen clipping

Post by anhnha » 26 Dec 2022, 08:08

I just tried to set the second monitor scale to 150% (from 100% initially) and it works. So the problem is due to different scaling between the first and second monitors. One thing I don't understand is that if I remove DPIScale it doesn't work for second monitor with scale of 100%.

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: Screen clipping

Post by boiler » 26 Dec 2022, 08:51

anhnha wrote: I added this line but now the capture regions become all black.

Code: Select all

 x*=round(x*1920/3840), y*=round(y*1080/2160)  ; <<<<<< This is the line added
By using *=, you are multiplying x by the result of your expression, which is already multiplying by x. So if x is 500, you have 500*round(500*1920/3840), which is 125000. Use the regular assignment operator := instead.

Same for y.

anhnha
Posts: 116
Joined: 08 Aug 2018, 02:46

Re: Screen clipping

Post by anhnha » 26 Dec 2022, 09:04

I got it from this by rommmcek .

Code: Select all

x*=round(x*secondMonWidth/firstMonWidth), y*=round(y*secondMonHight/firstMonHight)

Code: Select all

Use the regular assignment operator := instead.
Do you mean something like this?

Code: Select all

 firstMonWidth := 3480
 firstMonHight := 2160 
 secondMonWidth:= 1920
 secondMonHight:= 1080 
 x*=round(x*firstMonWidth/secondMonWidth), y*=round(y*secondMonHight/firstMonHight)
This does not work as well. Anyway, it's good that the program works fine if I set two monitors with the same scale factor.

User avatar
rommmcek
Posts: 1474
Joined: 15 Aug 2014, 15:18

Re: Screen clipping

Post by rommmcek » 26 Dec 2022, 10:15

x*=round(..) was obviously a Copy/Paste & quick edit blunder! I wonder how tank got any capture at all!

This was a proposal from a one monitor user perspective, being on a mount stupid after some capturing successes from different regions of a monitor.

From today's point of view (after anhnha discovered scaling as a problem), I wonder if this would work?

Code: Select all

Gdip_BitmapFromScreen(Screen=0, Raster="") {
 static firstMonWidth := 3480, firstMonHight := 2160
 if (Screen = 0)
 {
  Sysget, x, 76
  Sysget, y, 77 
  Sysget, w, 78
  Sysget, h, 79
  ws:= w, hs:= h
 }
 else if (Screen&1 != "")
 {
  Sysget, M, Monitor, %Screen%
  x:= MLeft, y:= MTop, w:=ws:= MRight-MLeft, h:=hs:= MBottom-MTop
 }
 else
 {
  StringSplit, S, Screen, |
  x:= S1, y:= S2, w:=ws:= S3, h:=hs:= S4
 }

 if (x = "") || (y = "") || (w = "") || (h = "")
  return -1

 if (x>firstMonWidth)
    x:= ScaleDim(x-firstMonWidth)+firstMonWidth, y:= ScaleDim(y), w:= ScaleDim(w), h:= ScaleDim(h)
 if (x<0 || y<0)
    x:= ScaleDim(x), y:= ScaleDim(y), w:= ScaleDim(w), h:= ScaleDim(h)
 if (y>firstMonHight)
    x:= ScaleDim(x), y:= ScaleDim(y-firstMonHight)+firstMonHight, w:= ScaleDim(w), h:= ScaleDim(h)

 chdc:= CreateCompatibleDC(), hbm:= CreateDIBSection(ws, hs, chdc), obm:= SelectObject(chdc, hbm), hhdc:= GetDC()
 StretchBlt(chdc, 0, 0, ws, hs, hhdc, x, y, w, h, Raster)
 ReleaseDC(hhdc)
 
 pBitmap:= Gdip_CreateBitmapFromHBITMAP(hbm)
 SelectObject(hhdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
 return pBitmap
}

ScaleDim(val) {
    static firstMonScale:= 150, SecondMonScale:= 100
    Return round(val/(firstMonScale/secondMonScale))
}
Note1: This is supposed to work only if the second monitor is not off set in regard to the first one i.e.:
- top borders of both monitors should be in one horizontal line (for sec. mon. on left or right)
- left borders of both monitors should be in one vertical line (for sec. mon. on top or bottom)

Note2: Values for first Monitor (Width and Hight) in pixels and values for first and second Monitor Scaling (in percent) are hardcoded so you have to edit them manually according to your configuration!
Last edited by rommmcek on 28 Dec 2022, 07:36, edited 16 times in total.

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: Screen clipping

Post by boiler » 26 Dec 2022, 20:55

anhnha wrote: Do you mean something like this?
No, I mean exactly what I said. Use := where you currently have *=.

anhnha
Posts: 116
Joined: 08 Aug 2018, 02:46

Re: Screen clipping

Post by anhnha » 26 Dec 2022, 22:18

Note: This is supposed to work only if the second monitor is aligned to the right of first one!
My second monitor is on the left of the first one. How should I modify that?

Post Reply

Return to “Scripts and Functions (v1)”