Screen clipping

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Screen clipping

Post by rommmcek » 28 Jan 2023, 07:18

@one1tick: Basically you have to replace original Gdip_BitmapFromScreen() with the edited one including ScaleDim().

Note: The new functions are stubs¹ so you have to adjust hardcoded static values (for both functions) according to your configurations!
__________
¹stub

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

Re: Screen clipping

Post by anhnha » 28 Jan 2023, 09:02

Hello,
I changed the function Gdip_BitmapFromScreen to this. You'll need to change screen heights, widths, and scales to your values.
EDIT: I didn't see rommmcek's post above. That was what I used.

Code: Select all

; Function				Gdip_BitmapFromScreen
; Description			Gets a gdi+ bitmap from the screen
;
; Screen				0 = All screens
;						Any numerical value = Just that screen
;						x|y|w|h = Take specific coordinates with a width and height
; Raster				raster operation code
;
; return      			If the function succeeds, the return value is a pointer to a gdi+ bitmap
;						-1:		one or more of x,y,w,h not passed properly
;
; notes					If no raster operation is specified, then SRCCOPY is used to the returned bitmap

;  firstMonScale := 150
;  secondMonScale:= 100
;  firstMonWidth := 3480
;  firstMonHight := 2160 
;  secondMonWidth:= 1080
;  secondMonHight:= 1920
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))
}

ajnasaboobacker
Posts: 1
Joined: 04 Feb 2023, 14:30

Re: Screen clipping

Post by ajnasaboobacker » 04 Feb 2023, 14:38

Can i have this complete script to start with, may be somewhere i can download

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 07 Feb 2023, 09:06

FanaticGuru wrote:
25 Oct 2017, 17:00
... cleaned up a lot of the code and made it more modular
Hello,
Thank you for this version. As it is very difficult to publish new features without altering the main script.
I managed to split the different modules to offer an easier script to extend with #Include Lib\newfeature.ahk.
I didn't manage to integrate the whole script but the mains parts are there.


how to install the different parts ?
Create a \Lib folder next to the RUN_ScreenCLip.ahk file and put all the new libraries or plugins there as well as the file gdip_all.ahk (by Marius ?ucan).
https://github.com/marius-sucan/AHK-GDIp-Library-Compilation/archive/refs/heads/master.zip

FG Screen Clipper (Plugin Edition)
You can try to unzip this starting package V1.7 : :arrow:
ScreenClipperStartingPackage_V1.7.zip
(119.93 KiB) Downloaded 154 times
or install the files manually (see below) ;)
main script: Run_ScreenClip.ahk
files in Lib folder: Gdip_all.ahk, FG_Header.ahk, FG_ScreenClip.ahk, FG_Context_Clip_Menu.ahk

File Name : RUN_ScreenCLip.ahk

Code: Select all

; File Name: RUN_ScreenCLip.ahk
; version : 1.7
; Main Run file
; autors : Fanatic Guru, Speedmaster

#Requires AutoHotkey v1.1.1+

; INITIALIZATION - ENVIROMENT
; -------------------------------------------------------------------------------------
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force  ; Ensures that only the last executed instance of script is running
; #NoTrayIcon  ; if you want no tray icon
Menu, tray, icon, %A_WinDir%\system32\mmcndmgr.dll,106  ; camera tray icon
; --------------------------------------------------------------------------------------
OnExit("ExitFGClipper")   ; clear the cache folder before exiting

;exit procedure
ExitFGClipper(){
global
loop 99
FileDelete, % CacheFolder "\" a_index ".png"         ; clear the cache folder
exitapp
}


; INCLUDE SECTION
; --------------------------------------------------------------------------------------
; -------------------- headers plugins
#Include lib\
#Include gdip_all.ahk               ; graphic library
#Include ImagePut.ahk               ; (for v1) graphic library
#Include FG_Header.ahk              ; change the default settings in this script.
#Include FG_ScreenClip.ahk          ; main script library
#Include FG_Context_Clip_Menu.ahk   ; there are 2 context menu in this file (full and basic)
;#Include JL_Shrink.ahk             ; double click to shrink or restore window size

; ------------------- footers plugins
;#Include SM_Borders.ahk            ; Press B to hide or show borders (toggle)
;#Include SM_RotateFlip.ahk			; Press R or Ctrl R to rotate current selected clip 90° or 180°
;#Include SM_Vis2.ahk               ; Press T to OCR (with tesseract.exe) (by iseahound)
;#Include SM_HideShowAll.ahk        ; Press F12 to Hide / Show all clip images
;#Include SM_Duplicate.ahk          ; Press D to duplicate selected clip image
;#Include SM_AlwaysOnBottom.ahk     ; Press PageDown / PageUp to make selected clip always on bottom or restore always on top
;#Include SM_Resizer.ahk            ; Press Crtl + Mouse wheel or Numpad Add/Sub to resize
;#Include GK_OCR.ahk				; Press Y to use internal Windows 10 OCR   (win 10+ only)
;#Include SM_Grayscale.ahk			; Press G to toggle grayscale
;#Include SM_MoveClip.ahk			; Press arrow or ctrl arrow keys to move clip by 10 or 1 pixel
;#Include SM_Trans.ahk			    ; Press Shift + Mouse wheel to make clip image transparent. Not compatible with other plugins. Use plugin duplicate to restore.
;#Include SM_DrawShape.ahk			; Press P to activate drawing mode. Use Shift Ctrl and Alt + mouse to draw shapes. Press Ctrl + P to abort.
; ---------------------------------------------------------------------------------------


; HOTKEYS GLOBAL SECTION
; -----------------------------------------------
;
#Lbutton::		;	<-- Clip Image Only
	SCW_ScreenClip2Win(SetClipboard:=false)
return

#^Lbutton::	;	<-- Clip Image and Copy to Clipboard
	SCW_ScreenClip2Win(SetClipboard:=true)
return

#!Lbutton::		;	<-- Clip Image and Save to File
	Hwnd := SCW_ScreenClip2Win(SetClipboard:=false)
	SCW_Win2File(Settings_SavePath,Hwnd)
return

#^!Lbutton::	;	<-- Clip Image, Copy to Clipboard, and Save to File
	Hwnd := SCW_ScreenClip2Win(SetClipboard:=true)
	SCW_Win2File(Settings_SavePath,Hwnd)
return

; HOTKEYS IF_WIN_ACTIVE SECTION
; ---------------------------------------------------------------------------------------
#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI

; REMOVE (DESTROY) SELECTED CLIP IMAGE
; ---------------------------------------------------------------------------------------
Esc::
WinGet, Hwnd, ID, A
MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")
   	Loop % MaxGuis {
        if (SCW_Reg("G" ++i "#HWND") = hwnd) {
	        currentgui := i
			break
		}}
	gui %currentgui%: destroy
	FileDelete, % CacheFolder "\" currentgui ".png"          ; also remove cached image (if there is one)
return

; RIGHT CLICK CONTEXT MENU
; ---------------------------------------------------------------------------------------
Rbutton:: Menu, FG_Context_Clip_2, Show

^c::				;	<-- (Screen Clipper) : Copy Active Clip to Clipboard  (true = remove borders)
	SCW_Win2Clipboard(true)
return
+^c::			;	<-- (Screen Clipper) : Copy Active Clip to Clipboard with Border (false = with borders)
	SCW_Win2Clipboard(false)
return
^s::				;	<-- (Screen Clipper) : Save Active Clip to File
	SCW_Win2File(Settings_SavePath)
return
+^s::			;	<-- (Screen Clipper) : Save Active Clip to File with Border
	SCW_Win2File(Settings_SavePath,,0)
return
#e::				;	<-- (Screen Clipper) : Save Active Clip to File and Email
	File := SCW_Win2File(Settings_SavePath)
	Email_AttachFile(File)
return

#IfWinActive
; -----------------------------------------------------------------------------------------------------------

-------------------------------------------------------

:arrow: Files to put in the Lib folder:

File Name : FG_Header.ahk
Spoiler
File Name : FG_ScreenClip.ahk
Spoiler
[Plugin] File Name: FG_Context_Clip_Menu.ahk
Spoiler
-

All suggestions or new plugins are welcome :D
Regards
Last edited by SpeedMaster on 23 Apr 2023, 12:05, edited 28 times in total.

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 09 Feb 2023, 05:18

[PLUGIN] Hide Show borders

how to install this plugin ?
1° download FG ScreenClipper at viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script ( RUN_ScreenCLip.ahk)
2° insert '#Include SM_Borders.ahk' in the 'include section' of the main script

Internal shortcuts:
Press B to hide/restore current selected clip image
Press Ctrl B to restore all hidden clip image borders
Gorgrak wrote:I have condensed your code a bit to make the hotkey section more readable
@Gorgrak Thank you, it helped me a lot to develop this plugin

File Name: SM_Borders.ahk

Code: Select all

/*--------------------------------------------------------------------------------------------------------------------
Hide Borders Plugin (by Speedmaster)
File Name : SM_Borders.ahk
version: 1.0
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script
2° insert '#Include SM_Borders.ahk' in the 'include section' of the main script ---> RUN_ScreenCLip.ahk

Note this plugin has internal default shortcuts (see below) that you can change 
or migrate in the #ifwinactive section of the main run script
*/---------------------------------------------------------------------------------------------------------------------


; DEFAULT SHORTCUTS ---------------------------------------------------
#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
b::SM_Borders()                 ; hide/restore current selected clip image  
^b::SM_RestoreAllBorders()      ; restore all hidden clip image borders
#IfWinActive
;--------------------------------------------------------------


; FUNCTIONS 
;------------------------------------- Hide/Show active window borders ------------------------------------------------
; function toggle borders 
SM_Borders() {
	WinGet, Hwnd, ID, A
	WinGet, Style, Style, ahk_id %Hwnd%
	if (Style & 0x2000)  ; toggle selected
	{
		WinSet, Style, -0x2000, A
		WinSet, Region, , A 
		return false
	}
	else                 ; retore selected
	{
		WinGetPos, X, Y, W, H,  ahk_id %Hwnd%
		W -= 6, H -= 6
		WinSet, Style, +0x2000, A
		WinSet, Region, 3-3 W%W% H%H%, A
		return true
	}	
}

; function to restore all hidden borders
SM_RestoreAllBorders() {
   MaxGuis := SCW_Reg("MaxGuis"), StartAfter := SCW_Reg("StartAfter")
   Loop, %MaxGuis%
   {
      StartAfter++
      Gui %StartAfter%: +lastfound
	  WinSet, Style, -0x2000
      WinSet, Region,
   }
   return false
}
Attachments
HSBorders.png
HSBorders.png (20.96 KiB) Viewed 3676 times
Last edited by SpeedMaster on 17 Feb 2023, 17:52, edited 6 times in total.

User avatar
Gorgrak
Posts: 23
Joined: 07 Dec 2015, 16:34

Re: Screen clipping

Post by Gorgrak » 09 Feb 2023, 06:47

@SpeedMaster
Yeah I love using Ternary to condense stuff into 1 line.

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 09 Feb 2023, 08:03

[PLUGIN] Rotate Flip v1.7

how to install this plugin ?
1° download FG ScreenClipper at viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script
3° Install plugin SM_Resizer.ahk at viewtopic.php?p=509598#p509598
4° insert "#Include SM_RotateFlip.ahk" in the INCLUDE SECTION of the main script ---> RUN_ScreenCLip.ahk

Internal shortcuts:
Press R to rotate 90° right (usefull for making vertical text)
Press Ctrl R to rotate 180° (usefull for turning a picture upside down)

Note:
  • You can try others numbers for the function SM_RotateFlip(1) (up to 6) to mirror or invert the clip image.
  • the plugin requires the SM_resizer.ahk plugin to be installed but it can also work in standalone by disabling the function call for resizing
  • the plugin use cached images stored in the "\temp" folder in the script directroy. The cache folder is cleared at startup and on exit.
File Name: SM_RotateFlip.ahk

Code: Select all

/*--------------------------------------------------------------------------------------------------------------------
[Plugin] Rotate/Flip (by Speedmaster)
File Name : SM_RotateFlip.ahk
version: 1.7   2023 04 23
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script
3° Install plugin SM_Resizer.ahk at https://www.autohotkey.com/boards/viewtopic.php?p=509598#p509598
4° insert "#Include SM_RotateFlip.ahk" in the INCLUDE SECTION of the main script ---> RUN_ScreenCLip.ahk

Note this plugin has internal default shortcuts (see below) that you can change 
or migrate in the #ifwinactive section of the main run script
*/---------------------------------------------------------------------------------------------------------------------


; DEFAULT SHORTCUTS ---------------------------------------------------
;Try others numbers (up to 6) to mirror or invert the clip image.
#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
r::SM_RotateFlip(1)    ; rotate 90° right (usefull for making vertical text)
^r::SM_RotateFlip(2)   ; rotate 180° (usefull to turn image)
#IfWinActive
;--------------------------------------------------------------

;-------- FUNTION TO ROTATE OR FLIP IMAGE ---------------------
SM_RotateFlip(type:=1){
global zlist, cachefolder

	imageput.gdiplusstartup()

	(!CacheFolder)&&CacheFolder:="temp"

	IfNotExist, %CacheFolder%
		FileCreateDir, %CacheFolder%
		if (ErrorLevel) {
			CacheFolder:=A_temp
        }

	WinGet, hwnd, ID, A
	MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")		
	Loop % MaxGuis {
		if (SCW_Reg("G" ++i "#HWND") = hwnd) {
			currentgui := i
			break
		}
	}	
	
	winGetPos, X, Y, W, H, ahk_id %Hwnd%
	x:=x+3, y:=y+3, w:=w-6, h:=h-6
	imgg:=CacheFolder "\" currentgui ".png"
	if (!FileExist(imgg)) {
		pBitmap := Gdip_BitmapFromScreen(X "|" Y "|" W "|" H)
		FileName := currentgui ".PNG"
		Gdip_SaveBitmapToFile(pBitmap, CacheFolder "\" FileName)
		imgg:=CacheFolder "\" FileName
	}

	pBitmap:=Gdip_CreateBitmapFromFileSimplified(imgg)
	Gdip_ImageRotateFlip(pBitmap, type) 
	WinSet, Style, -0x2000, A
	WinSet, Region, , A   ; restore hidden borders (if any) before writing image in gui

	Gdip_SaveBitmapToFile(pBitmap, imgg)

	if !(zlist["Scaled"][currentgui]) {
		SCW_CreateLayeredWinMod(currentgui,pBitmap,x,y)
    }
	if (zlist["Scaled"][currentgui]) {
		sm_resize("1","0")                        ; desactivate this line if the resizer plugin is not installed
	}

	Gdip_DisposeImage(pBitmap)
	imageput.gdiplusShutdown()		
}
Attachments
Rotate.png
Rotate.png (229.65 KiB) Viewed 3638 times
Last edited by SpeedMaster on 23 Apr 2023, 13:37, edited 9 times in total.

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

Re: Screen clipping

Post by Avastgard » 09 Feb 2023, 11:55

Awesome, thanks for this!

But I can't get it to work. The yellow square shows, but disappears once I let go of LButton and doesn't clip the image.

Could you further explain how to install the plugin? Here's the folder structure I have:

Code: Select all

...ScreenClipper\
	Lib\
	RUN_ScreenCLip.ahk

...Lib\
	FG_Context_Clip_Menu.ahk"
	FG_Header.ahk"
	FG_ScreenClip.ahk"
	Gdip.ahk"
	SM_RotateFlip.ahk"

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 09 Feb 2023, 14:43

Avastgard wrote:
09 Feb 2023, 11:55
I can't get it to work. The yellow square shows, but disappears once I let go of LButton and doesn't clip the image.
The folder and file structure is correct. :think:
It seems that the GDI library I had specified was not compatible with the AHK U64 version. :problem:
I tested with the library Gdip_all (from Marius Șucan) and it woks fine now. https://github.com/marius-sucan/AHK-GDIp-Library-Compilation
I updated the previous links to work with gdip_all.
Thank you for reporting this problem. :thumbup:
I hope it will work now.:roll:

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 10 Feb 2023, 10:24

Hello,
I made some necessary updates in the starting package. viewtopic.php?p=506077#p506077
changes:
  • added version for the starting package (v1.1)
  • added Global var GuiNum in the header file
  • The context clip menu is now modified to behave like a plugin . Bug fix: removed "return" + menus handlers are now functions
Regards

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

Re: Screen clipping

Post by Avastgard » 13 Feb 2023, 09:25

Thanks for the update, @SpeedMaster!

Do you plan to add OCR functionality?

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 13 Feb 2023, 16:28

Avastgard wrote:
13 Feb 2023, 09:25
Do you plan to add OCR functionality?
No but this should not be too hard to implement since there is already a library available. (Vis2 OCR by iseahound :geek:)
I have written a plugin (wrapper) that should do the trick. :angel:
See below...
Not fully tested yet. Can you tell me if it works ? :roll:

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 13 Feb 2023, 16:38

[PLUGIN] OCR v1.3.02 (with Tesseract)

how to install this plugin ?
1° download ScreenClipperStartingPackage.zip at viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script (the folder where "RUN_ScreenCLip.ahk" file is located)
3° insert entry '#Include SM_Vis2.ahk' in the 'include section' of the main script ---> RUN_ScreenCLip.ahk
4° download Vis2 library (by iseahound) at https://github.com/iseahound/Vis2
5° copy the "bin" folder in the main Run script directory (the folder where "RUN_ScreenCLip.ahk" file is located)
6° insert Vis2.ahk, Json.ahk and Imageput.ahk in the \Lib folder
7° select a clip image and press T then select area for OCR

Internal shortcuts:
Press T to save OCR text in clipboard

Warning: This plugin can freeze your screen if it has not been properly installed
:arrow: make sure that the Bin folder is in the main RUN script folder and that all other libraries are in the Lib folder before trying it.

File Name: SM_Vis2.ahk

Code: Select all

/*--------------------------------------------------------------------------------------------------------------------
File Name : SM_Vis2.ahk 
version: 1.3.02
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download ScreenClipperStartingPackage at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script (the folder where "RUN_ScreenCLip.ahk" file is located)
3° insert entry '#Include SM_Vis2.ahk' in the 'include section' of the main script ---> RUN_ScreenCLip.ahk
4° download Vis2 library (by iseahound) at https://github.com/iseahound/Vis2
5° copy the "bin" folder in the main Run script directory (the folder where "RUN_ScreenCLip.ahk" file is located)
6° insert Vis2.ahk, Json.ahk and Imageput.ahk in the \Lib folder
7° select a clip image and press T then select area for OCR

Note this plugin has internal default shortcuts (see below) that you can change 
or migrate in the #ifwinactive section of the main run script
*/---------------------------------------------------------------------------------------------------------------------

#Include Vis2.ahk     ; by iseahound   https://github.com/iseahound/Vis2

; DEFAULT SHORTCUTS ---------------------------------------------------
;Press T to select with mouse area for ocr.

#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
t::SM_OCR(1)                    ; sm_ocr(1)= save to clipboard and show clipboard in message box  -   sm_ocr(2) = save to clipboard and open clipboard in notepad 
#IfWinActive

;-------- FUNCTION SM_OCR ---------------------
;HELP: 
;     if output=1 .......... save to clipboard and show clipboard in message box
;     if output=2 .......... save to clipboard and open clipboard in notepad 
;     if RemoveEmptyLines=true ........... save to clipboard and remove empty lines from clipboard

SM_OCR(output:="2", RemoveEmptyLines:=true){
	if !pToken := Gdip_Startup()
	{
		MsgBox, 64, GDI+ error, GDI+ failed to start. Please ensure you have GDI+ on your system.
		return
	}
	if (output=1) {
		ocr()
		if RemoveEmptyLines
            clipboard:=RegExReplace(clipboard, "`am)^\R")
		msgbox, % clipboard
}
else if (output=2) {	
	ocr()
sleep, 100
	if RemoveEmptyLines
	   clipboard:=RegExReplace(clipboard, "`am)^\R")
	Run Notepad.exe
	Sleep, 100
	SendInput ^v
	}
}
Last edited by SpeedMaster on 02 Mar 2023, 05:50, edited 9 times in total.

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

Re: Screen clipping

Post by Avastgard » 15 Feb 2023, 06:58

Thanks, it appears to be working. However, OCR is very slow and it is a very important feature to me. I have been using Joe Glines' version (Window Snipping.ahk for a while, which is less stable (script needs to be reloaded every now and then), but has a much faster OCR.

By the way, about the rotating plugin:
SpeedMaster wrote:
09 Feb 2023, 08:03
[PLUGIN] Rotate Flip

how to install this plugin ?
1° download FG ScreenClipper at viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script ( RUN_ScreenCLip.ahk)
2° insert #Include SM_RotateFlip.ahk in the INCLUDE SECTION of the main script ( RUN_ScreenCLip.ahk)

Internal shortcuts:
Press R to rotate 90° right (usefull for making vertical text)
Press Ctrl R to rotate 180° (usefull for turning a picture upside down)
Note: You can try others numbers (up to 6) to mirror or invert the clip image.

File Name: SM_RotateFlip.ahk

Code: Select all

/*--------------------------------------------------------------------------------------------------------------------
[Plugin] Rotate/Flip (by Speedmaster)
File Name : SM_RotateFlip.ahk
version: 1.0
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script
2° insert "#Include SM_RotateFlip.ahk" in the INCLUDE SECTION of the main script ---> RUN_ScreenCLip.ahk

Note this plugin has internal default shortcuts (see below) that you can change 
or migrate in the #ifwinactive section of the main run script
*/---------------------------------------------------------------------------------------------------------------------


; DEFAULT SHORTCUTS ---------------------------------------------------
;Try others numbers (up to 6) to mirror or invert the clip image.
#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
r::SM_RotateFlip(1)    ; rotate 90° right (usefull for making vertical text)
^r::SM_RotateFlip(2)   ; rotate 180° (usefull to turn image)
#IfWinActive
;--------------------------------------------------------------

;-------- FUNTION TO ROTATE OR FLIP IMAGE ---------------------
SM_RotateFlip(type:=1){
WinGet, hwnd, ID, ahk_class AutoHotkeyGUI
	Loop 99 {
		Gui %A_Index%: +LastFound
		if WinExist() = hwnd {
			currentgui := A_Index
			break
		}
	}
winGetPos, X, Y, W, H, ahk_id %Hwnd%
x:=x+3, y:=y+3, w:=w-6, h:=h-6
pToken := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen(X "|" Y "|" W "|" H)
Gdip_ImageRotateFlip(pBitmap, type) 
WinSet, Style, -0x2000, A
WinSet, Region, , A   ; restore hidden borders (if any) before writing image in gui
SCW_CreateLayeredWinMod(currentgui,pBitmap,x,y)
Gdip_Shutdown(pToken)
}

R and Ctrl + R work fine for me, but the number options don't. Do I have to use NumPad numbers to make it work?

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 15 Feb 2023, 16:50

Avastgard wrote:
15 Feb 2023, 06:58
Thanks, it appears to be working. However, OCR is very slow...
Yep, it's really too slow when specifying coordinates :cry: , but it's much faster when you do it manually with Vis2's own selector. ;)
I updated the previous SM_OCR plugin to v1.2 viewtopic.php?f=6&t=12088&start=240#p507222
New function: SM_OCR(output:="2", RemoveEmptyLines:=true)
Now when you press T the internal selector is launched to manually select with the mouse the region to OCR.
I also added an option to delete empty lines and an option to output text to notepad (output=2) or the message box (output=1).
Avastgard wrote:
15 Feb 2023, 06:58
By the way, about the rotating plugin:
R and Ctrl + R work fine for me, but the number options don't. Do I have to use NumPad numbers to make it work?
No, this has nothing to do with the numeric keypad, it is rather a parameter for the type of rotation SM_RotateFlip(type:=1). (type 1 to 6)
You have to create a keyboard shortcut in the plugin to test all the other possibilities.
The other possibilities are not really interesting, that's why I didn't incorporate them in the script.

here is a complete list of shortcuts to try
Spoiler
Regards
Last edited by SpeedMaster on 17 Feb 2023, 17:55, edited 1 time in total.

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 17 Feb 2023, 17:46

SpeedMaster wrote:
13 Feb 2023, 16:38
Press T to save OCR text in clipboard
After some tests I noticed that the plugin for ocr (SM_Vis2) was unstable and freezing the screen. :cry:
I added a line in the plugin script to force the launch of gdip, the problem seems to be solved now. :roll: posting.php?mode=quote&f=6&p=507222#pr507222
Regard

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 17 Feb 2023, 18:16

[PLUGIN] Hide/Show All Clip Images v1.0

how to install this plugin ?
1° download FG ScreenClipper v1.2+ at viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main RUN script
2° insert this line " #Include SM_HideShowAll.ahk " in the INCLUDE SECTION of the main script ---> RUN_ScreenCLip.ahk

Internal Global shortcut:
Press F12 to hide or show all clip images.

Note: you can always change the keyboard shortcut by the one you like, taking care not to conflict with the shortcuts of other plugins

File Name: SM_HideShowAll.ahk

Code: Select all

/*--------------------------------------------------------------------------------------------------------------------
[Plugin] Hide/Show (toggle) All Clip Images  (by Speedmaster)
File Name : SM_HideShowAll.ahk
version: 1.0.00
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script
2° insert line " #Include SM_HideShowAll.ahk " in the INCLUDE SECTION of the main script ---> RUN_ScreenCLip.ahk

Note this plugin has internal default shortcuts (see below) that you can change 
or migrate in the HOTKEYS GLOBAL SECTION of the main RUN script
*/---------------------------------------------------------------------------------------------------------------------



; HOTKEYS GLOBAL SECTION
;-----------------------------------------------

~F12::SM_HideShowAll()     ; toggle visibility of all clip images





;-------- FUNCTION SM_HideShowAll() ---------------------
;HELP: 
;     this function has a static true/false variable that toggle visibility of all clip images

SM_HideShowAll() {
static HideAll
HideAll:=!HideAll
MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")
	Loop, %MaxGuis%
	{
		++i
		Gui %i%: +LastFound
		
		if (HideAll) {
		    if (SCW_Reg("G" i "#HWND") = WinExist()) 
				Gui %i%: hide
		}
		else 
		    if (SCW_Reg("G" i "#HWND") = WinExist()) 
				Gui %i%: show, NA
	}
}	
Cheers
Last edited by SpeedMaster on 25 Feb 2023, 19:21, edited 1 time in total.

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 18 Feb 2023, 12:07

SpeedMaster wrote:
17 Feb 2023, 18:16
[PLUGIN] Hide/Show All Clip Images
Press F12 to hide or show all clip images.
I noticed that the hide/show all plugin also showed the images that had been previously closed. :crazy:
I updated the main RUN file and the context clip menu plugin so that it would destroy the window properly instead of hiding it.
Main files update v1.3 : viewtopic.php?p=506077#p506077

cheers

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 24 Feb 2023, 17:47

[PLUGIN] Duplicate v1.2

how to install this plugin ?
1° download FG ScreenClipper v1.2+ at viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main RUN script
3° insert this line " #Include SM_Duplicate.ahk " in the INCLUDE SECTION of the main script ---> RUN_ScreenCLip.ahk
4° Install plugin SM_Resizer.ahk at viewtopic.php?p=509598#p509598

Internal shortcut:
Press D to use selected image area for making a new clip image. ( d for duplicate )

Note: the new duplicated image is placed just in front of the selected clip image giving the illusion that nothing happened...
:arrow: Please move the new clip image with the mouse to check if everything went well

File Name: SM_Duplicate.ahk

Code: Select all

/*--------------------------------------------------------------------------------------------------------------------
[Plugin] Duplicate (by Speedmaster)
File Name : SM_Duplicate.ahk
version: 1.2
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main RUN script
3° insert "#Include SM_Duplicate.ahk" in the INCLUDE SECTION of the main RUN script ---> RUN_ScreenCLip.ahk
4° Install plugin SM_Resizer.ahk at https://www.autohotkey.com/boards/viewtopic.php?p=509598#p509598

Note this plugin has internal default shortcuts (see below) that you can change 
or migrate in the #ifwinactive section of the main run script
*/---------------------------------------------------------------------------------------------------------------------


; DEFAULT SHORTCUT ----- (#ifwinactive section)----------------------------------------------
#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
d::SM_Duplicate()               ; duplicate (use selected image area for making a new clip image)
#IfWinActive

;-----FUNCTION DUPLICATE AREA------------------------------------------
SM_Duplicate(DuplicateToPos:=""){
	global GuiNum
	SCW_ScreenClip2Win(SetClipboard:=0)
	if (DuplicateToPos)
	guinum:=DuplicateToPos
	WinGetPos , OutX, OutY, OutWidth, OutHeight, A
	OutX:=OutX+3, OutY:=OutY+3, OutWidth:=OutWidth-6, OutHeight:=OutHeight-6
	Area := OutX "|" OutY "|" OutWidth "|" OutHeight
	StringSplit, v, Area, |
	if (v3 < 10 and v4 < 10)   ; too small area
		return
    imageput.gdiplusstartup()
	pBitmap := Gdip_BitmapFromScreen(Area)
	hwnd := SCW_CreateLayeredWinMod(guinum,pBitmap,v1,v2, SCW_Reg("DrawCloseButton"))
	Gdip_DisposeImage(pBitmap)
	imageput.gdiplusShutdown()	
}	

Cheers
Attachments
duplicate.PNG
duplicate.PNG (167.14 KiB) Viewed 2961 times
Last edited by SpeedMaster on 14 Mar 2023, 15:22, edited 1 time in total.

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 25 Feb 2023, 19:00

[PLUGIN] Shrink v1.0 (by Juho-Lee)

Usage:
Double click to shrink or restore the window size

how to install this plugin ?
1° download FG ScreenClipper v1.2+ at viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main RUN script
3° Note: this is a header plugin which means that it must be loaded before the plugins that contain shortcuts
insert this line "#Include JL_Shrink.ahk" in the INCLUDE SECTION of the main RUN script just after
the line that contains "#Include Fg_Context_Clip_Menu.ahk" for it to work properly

like this:
#Include gdip_all.ahk
#Include FG_Header.ahk
#Include FG_ScreenClip.ahk
#Include FG_Context_Clip_Menu.ahk
#Include JL_Shrink.ahk
<------- insert the line entry here

Internal shortcut:
DOUBLE CLICK to shrink the window and double click again to restore it. 8-)

File Name: JL_Shrink.ahk

Code: Select all

/*--------------------------------------------------------------------------------------------------------------------
[Plugin] Shrink  (by Juho-Lee [url]https://juho-lee.com[/url])
File Name : JL_Shrink.ahk
version: 1.0
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script
3° Note: this is a header plugin which means that it must be loaded before the plugins that contain shortcuts
   insert this line "#Include JL_Shrink.ahk" in the INCLUDE SECTION of the main RUN script just after 
   the line that contains "#Include Fg_Context_Clip_Menu.ahk" for it to work properly

   like this:
   #Include gdip_all.ahk               
   #Include FG_Header.ahk 
   #Include FG_ScreenClip.ahk 
   #Include FG_Context_Clip_Menu.ahk
   #Include JL_Shrink.ahk            <------- insert the line entry here
*/---------------------------------------------------------------------------------------------------------------------


; DEFAULT SHORTCUT ---------------------------------------------------
;double click to downsize. Double click again to resize.

OnMessage(0x0203, "WM_LBUTTONDBLCLK") 
WM_LBUTTONDBLCLK() { 
    
   global
    
   WinGet, TempID, , A
   WinGetPos, , , Temp_Width, Temp_Height, A 
   
   If (Temp_Width = 30 && Temp_Height = 30) {
      WinMove, A, , , , % %TempID%_Width, % %TempID%_Height
   } else {
   %TempID%_Width := Temp_Width
   %TempID%_Height := Temp_Height
   WinMove, A, , , , 30, 30
   }      

}
Learn more about the author at https://juho-lee.com
Regards

Post Reply

Return to “Scripts and Functions (v1)”