1. [module] Screen clipping - modular form of screen clipping script below. Easy to use & implement in any script.
2. Screen clipping - Basic screen clipping script. Saves selected area to clipboard.
The goal here was to create small, practical screen clipping script. Made obsolete by [module] Screen clipping.
3. [module] ScreenClip2Win - creates always on top windows from screen clippings.
4. Screen clipping collector - not maintained any more
Saves selected area to virtual container. Collects up to 4 pictures (screen clippings), and allows you to paste
them later. Always preserves current clipboard. Can be modified to collect much more pictures. I found this script useful when
extracting informations from web pages, documents, or when editing pictures. Please read description in script!
See also:
- Screen Capture with Transparent Windows and Mouse Cursor by Sean
- Sumon's branch of ScreenClipping script
For all scripts/modules: thanks to: Sean, wilhberg, and others...
Screen clipping - recommendation --> use the [module] Screen clipping
;===Description========================================================================
/*
Screen clipping script. Saves selected area to clipboard.
AHK forum location: http://www.autohotkey.com/forum/viewtopic.php?t=49950
Put together by Learning one
Thanks: Sean, wilhberg, and others...
To select area:
1. press Control + Left mouse button
2. drag mouse
3. release Control and Left mouse button
This area will be saved to clipboard.
Press Control + v to paste it.
Press Esc to exit.
*/
;===Functions==========================================================================
CaptureScreen(aRect)
{
StringSplit, rt, aRect, `,, %A_Space%%A_Tab%
nL := rt1
nT := rt2
nW := rt3 - rt1
nH := rt4 - rt2
znW := rt5
znH := rt6
mDC := DllCall("CreateCompatibleDC", "Uint", 0)
hBM := CreateDIBSection(mDC, nW, nH)
oBM := DllCall("SelectObject", "Uint", mDC, "Uint", hBM)
hDC := DllCall("GetDC", "Uint", 0)
DllCall("BitBlt", "Uint", mDC, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", hDC, "int", nL, "int", nT, "Uint", 0x40000000 | 0x00CC0020)
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
DllCall("SelectObject", "Uint", mDC, "Uint", oBM)
DllCall("DeleteDC", "Uint", mDC)
SetClipboardData(hBM)
}
CreateDIBSection(hDC, nW, nH, bpp = 32, ByRef pBits = "")
{
NumPut(VarSetCapacity(bi, 40, 0), bi)
NumPut(nW, bi, 4)
NumPut(nH, bi, 8)
NumPut(bpp, NumPut(1, bi, 12, "UShort"), 0, "Ushort")
NumPut(0, bi,16)
Return DllCall("gdi32\CreateDIBSection", "Uint", hDC, "Uint", &bi, "Uint", 0, "UintP", pBits, "Uint", 0, "Uint", 0)
}
SetClipboardData(hBitmap)
{
DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi)
hDIB := DllCall("GlobalAlloc", "Uint", 2, "Uint", 40+NumGet(oi,44))
pDIB := DllCall("GlobalLock", "Uint", hDIB)
DllCall("RtlMoveMemory", "Uint", pDIB, "Uint", &oi+24, "Uint", 40)
DllCall("RtlMoveMemory", "Uint", pDIB+40, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44))
DllCall("GlobalUnlock", "Uint", hDIB)
DllCall("DeleteObject", "Uint", hBitmap)
DllCall("OpenClipboard", "Uint", 0)
DllCall("EmptyClipboard")
DllCall("SetClipboardData", "Uint", 8, "Uint", hDIB)
DllCall("CloseClipboard")
}
;===Hotkeys=========================================================================
^Lbutton::
CoordMode, Mouse ,Screen
MouseGetPos, MX, MY
Gui, +AlwaysOnTop -caption +Border +ToolWindow +LastFound
WinSet, Transparent, 80
Gui, Color, lime
While, (GetKeyState("LButton", "p"))
{
MouseGetPos, MXend, MYend
Send {control up}
w := abs(MX - MXend)
h := abs(MY - MYend)
If ( MX < MXend )
X := MX
Else
X := MXend
If ( MY < MYend )
Y := MY
Else
Y := MYend
Gui, Show, x%X% y%Y% w%w% h%h%
Sleep, 10
}
MouseGetPos, MXend, MYend
Gui, Destroy
If ( MX > MXend )
{
temp := MX
MX := MXend
MXend := temp
}
If ( MY > MYend )
{
temp := MY
MY := MYend
MYend := temp
}
Area = %MX%, %MY%, %MXend%, %MYend%
Sleep, 100 ; if omitted, GUI sometimes stays in picture
CaptureScreen(Area) ; Saves selected area without cursor in Clipboard.
Return
Escape::
Suspend
ExitApp
Screen clipping collector
;===Description=========================================================================
/*
Screen clipping collector v1.01 by Learning one
AHK forum location: http://www.autohotkey.com/forum/viewtopic.php?t=49950
Thanks: Chris, Sean, wilhberg, and others...
Saves selected area to virtual container. Collects up to 4 pictures (screen clippings), and allows you to paste
them later. Always preserves current clipboard. Can be modified to collect much more pictures, but I don't think
that's practical. It's better to paste collected pictures, empty container, and start collecting again.
After each successful screen clipping, small number will appear on center of the screen, indicating saved
picture's number. You can even apply color effect to your screen clipping by setting ApplyColorEffect = yes.
In that case, screen clipping will be merged with selection's color and transparency. Try it, just for fun.
I know that I should make GUI (especially for this color effect), but I currently don't have time and will
to do that. For now, you can change script's settings in Settings section, a few lines lower. I tried to write
this script in "newbie frendly style" so almost everyone can study it, and modify as he wish.
I found this script useful when extracting informations from web pages, documents, or when editing pictures.
Tested and works in MS Word, PowerPoint, Excel, OneNote and Paint. If it does not work properly, see description
for AppendClipboardSleep variable in Settings section.
Due to clipboard -> virtual container -> clipboard data transfer, this script might not work in some applications.
In that case, use my other script, "Screen clipping". Also see description for AppendClipboardSleep variable.
Hotkeys:
Control + Lbutton Click and drag to select area to clip (once you started selecting, you can release Control)
C Cancel while selecting area (abort) (it is not real hotkey, it is condition, if statement)
Control + 1-4 Paste 1-4. picture
Control + E Empty picture container
Escape Exit
*/
;===Settings - change this if you wish==================================================
SelectionColor = yellow ; Allowed values: valid color name (see www.autohotkey.com/docs/commands/Progress.htm#colors)
SelectionTransparency = 80 ; Allowed values: 0 - 255
ApplyColorEffect = no ; Allowed values: yes, no
PhotoTrayIcon = yes ; Allowed values: yes, no
ShowHotkeys = yes ; Allowed values: yes, no
AppendClipboardSleep = 80 ; Control + 1-4 sometimes pastes your Clipboard, not picture. To fix this, you can: 1) simply press this hotkey again or 2) increase this value. Recommended values: 20 - 500
;===Auto-execute========================================================================
if PhotoTrayIcon = yes
Menu, Tray, Icon, Shell32.dll, 140 ; photo icon
StringTrimRight, Sname, A_ScriptName, 4
Menu, Tray, Tip, %Sname%
if ShowHotkeys = yes
{
TrayTip, Screen clipping collector - Hotkeys,
(
Control + Lbutton`tSelect area
C`t`t`tCancel while selecting area
Control + 1-4`t`tPaste 1-4. picture
Control + E`t`tEmpty container
Escape`t`t`tExit
), 10, 1
}
;===Functions===========================================================================
CaptureScreen(aRect)
{
StringSplit, rt, aRect, `,, %A_Space%%A_Tab%
nL := rt1
nT := rt2
nW := rt3 - rt1
nH := rt4 - rt2
znW := rt5
znH := rt6
mDC := DllCall("CreateCompatibleDC", "Uint", 0)
hBM := CreateDIBSection(mDC, nW, nH)
oBM := DllCall("SelectObject", "Uint", mDC, "Uint", hBM)
hDC := DllCall("GetDC", "Uint", 0)
DllCall("BitBlt", "Uint", mDC, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", hDC, "int", nL, "int", nT, "Uint", 0x40000000 | 0x00CC0020)
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
DllCall("SelectObject", "Uint", mDC, "Uint", oBM)
DllCall("DeleteDC", "Uint", mDC)
SetClipboardData(hBM)
}
CreateDIBSection(hDC, nW, nH, bpp = 32, ByRef pBits = "")
{
NumPut(VarSetCapacity(bi, 40, 0), bi)
NumPut(nW, bi, 4)
NumPut(nH, bi, 8)
NumPut(bpp, NumPut(1, bi, 12, "UShort"), 0, "Ushort")
NumPut(0, bi,16)
Return DllCall("gdi32\CreateDIBSection", "Uint", hDC, "Uint", &bi, "Uint", 0, "UintP", pBits, "Uint", 0, "Uint", 0)
}
SetClipboardData(hBitmap)
{
DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi)
hDIB := DllCall("GlobalAlloc", "Uint", 2, "Uint", 40+NumGet(oi,44))
pDIB := DllCall("GlobalLock", "Uint", hDIB)
DllCall("RtlMoveMemory", "Uint", pDIB, "Uint", &oi+24, "Uint", 40)
DllCall("RtlMoveMemory", "Uint", pDIB+40, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44))
DllCall("GlobalUnlock", "Uint", hDIB)
DllCall("DeleteObject", "Uint", hBitmap)
DllCall("OpenClipboard", "Uint", 0)
DllCall("EmptyClipboard")
DllCall("SetClipboardData", "Uint", 8, "Uint", hDIB)
DllCall("CloseClipboard")
}
;===Hotkeys=============================================================================
^Lbutton:: ; Click and drag to select area to clip
no++
if no > 4
{
MsgBox, 52, Container full!, Screen clipping container is full.`nPressing Control + E will empty it.`n`nDo you want to empty container now?`n(You will lose all 4 screen clippings)
IfMsgBox, yes
{
Progress, m2 b fs13 zh0 WMn700, Container emptied!
Gosub, EmptyAndProgressOff
Return
}
Else
Return
}
CoordMode, Mouse ,Screen
MouseGetPos, MX, MY
Gui, +AlwaysOnTop -caption +Border +ToolWindow +LastFound
WinSet, Transparent, %SelectionTransparency%
Gui, Color, %SelectionColor%
While, (GetKeyState("LButton", "p"))
{
MouseGetPos, MXend, MYend
Send {control up}
w := abs(MX - MXend)
h := abs(MY - MYend)
If (MX < MXend)
X := MX
Else
X := MXend
If (MY < MYend)
Y := MY
Else
Y := MYend
Gui, Show, x%X% y%Y% w%w% h%h%
if (GetKeyState("c", "p")) ; Cancel while selecting area (abort)
{
Gui, Destroy
no--
Send, {control up}{c up}{LButton up}
Return
}
Sleep, 10
}
MouseGetPos, MXend, MYend
if ApplyColorEffect = yes
{
Gui, hide
Gui, -Border
Gui, Show, x%X% y%Y% w%w% h%h%
}
if ApplyColorEffect = no
Gui, Destroy
If (MX > MXend)
{
temp := MX
MX := MXend
MXend := temp
}
If (MY > MYend)
{
temp := MY
MY := MYend
MYend := temp
}
Area = %MX%, %MY%, %MXend%, %MYend%
OriginalClipboard = %ClipboardAll% ; save
Sleep, 100 ; if omitted, GUI sometimes stays in picture
CaptureScreen(Area) ; Saves selected area without cursor in Clipboard.
if ApplyColorEffect = yes
Gui, Destroy
Picture%no% := ClipboardAll
Progress, m2 b fs13 zh0 WMn700 w40, %no%
Sleep, 600
Clipboard = %OriginalClipboard% ; restore
Progress, off
Return
^1:: ; Paste 1. picture
^2:: ; Paste 2. picture
^3:: ; Paste 3. picture
^4:: ; Paste 4. picture
Gosub, PastePicture
Return
^e:: ; Empty picture container and restart numbering
Progress, m2 b fs13 zh0 WMn700, Container emptied!
IfWinExist, Container full!
{
SetControlDelay, -1
ControlClick, &No, Container full!
SetControlDelay, 20
}
Gosub, EmptyAndProgressOff
Return
Escape:: ; Exit
Suspend
ExitApp
;===Subroutines=========================================================================
PastePicture:
OriginalClipboard = %ClipboardAll% ; save
StringTrimLeft, PicNo, A_ThisHotkey, 1
if PicNo = 1
Clipboard := Picture1
Else if PicNo = 2
Clipboard := Picture2
Else if PicNo = 3
Clipboard := Picture3
Else if PicNo = 4
Clipboard := Picture4
Sleep, %AppendClipboardSleep% ; if omitted, next command sometimes paste OriginalClipboard, not Picture! Use Clipboard := "" and ClipWait if you wish.
Send, ^v
Clipboard = %OriginalClipboard% ; restore
Return
EmptyAndProgressOff:
Picture1 =
Picture2 =
Picture3 =
Picture4 =
no = 0
Sleep, 900
Progress, off
Return




