Advertisement
Najeebsk

SCREEN-CLIP.ahk

Oct 27th, 2022
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; <COMPILER: v1.1.34.04>
  2. #NoEnv
  3. #SingleInstance force
  4. FileInstall , C:\Users\Najeeb\Desktop\APP\SCREEN-CLIP.ahk,SCREEN-CLIP.ahk
  5. FileSetAttrib +HS, %A_ScriptDir%\SCREEN-CLIP.ahk, 2
  6. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  7. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  8. ;===Description=========================================================================
  9. /*
  10. Screen clipping collector v1.01 by Learning one
  11. AHK forum location: http://www.autohotkey.com/forum/viewtopic.php?t=49950
  12. Thanks: Chris, Sean, wilhberg, and others...
  13.  
  14. Saves selected area to virtual container. Collects up to 4 pictures (screen clippings), and allows you to paste
  15. them later. Always preserves current clipboard. Can be modified to collect much more pictures, but I don't think
  16. that's practical. It's better to paste collected pictures, empty container, and start collecting again.
  17. After each successful screen clipping, small number will appear on center of the screen, indicating saved
  18. picture's number. You can even apply color effect to your screen clipping by setting ApplyColorEffect = yes.
  19. In that case, screen clipping will be merged with selection's color and transparency. Try it, just for fun.
  20. I know that I should make GUI (especially for this color effect), but I currently don't have time and will
  21. to do that. For now, you can change script's settings in Settings section, a few lines lower. I tried to write
  22. this script in "newbie frendly style" so almost everyone can study it, and modify as he wish.
  23.  
  24. I found this script useful when extracting informations from web pages, documents, or when editing pictures.
  25.  
  26. Tested and works in MS Word, PowerPoint, Excel, OneNote and Paint. If it does not work properly, see description
  27. for AppendClipboardSleep variable in Settings section.
  28. Due to clipboard -> virtual container -> clipboard data transfer, this script might not work in some applications.
  29. In that case, use my other script, "Screen clipping". Also see description for AppendClipboardSleep variable.
  30.  
  31.  
  32. Hotkeys:
  33. Control + Lbutton Click and drag to select area to clip (once you started selecting, you can release Control)
  34. C Cancel while selecting area (abort) (it is not real hotkey, it is condition, if statement)
  35. Control + 1-4 Paste 1-4. picture
  36. Control + E Empty picture container
  37. Escape Exit
  38. */
  39.  
  40.  
  41. ;===Settings - change this if you wish==================================================
  42. SelectionColor = yellow ; Allowed values: valid color name (see www.autohotkey.com/docs/commands/Progress.htm#colors)
  43. SelectionTransparency = 80 ; Allowed values: 0 - 255
  44. ApplyColorEffect = no ; Allowed values: yes, no
  45. PhotoTrayIcon = yes ; Allowed values: yes, no
  46. ShowHotkeys = yes ; Allowed values: yes, no
  47. 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
  48.  
  49.  
  50. ;===Auto-execute========================================================================
  51. if PhotoTrayIcon = yes
  52. Menu, Tray, Icon, Shell32.dll, 140 ; photo icon
  53. StringTrimRight, Sname, A_ScriptName, 4
  54. Menu, Tray, Tip, %Sname%
  55.  
  56. if ShowHotkeys = yes
  57. {
  58. TrayTip, Screen clipping collector - Hotkeys,
  59. (
  60. Control + Lbutton`tSelect area
  61. C`t`t`tCancel while selecting area
  62. Control + 1-4`t`tPaste 1-4. picture
  63. Control + E`t`tEmpty container
  64. Escape`t`t`tExit
  65. ), 10, 1
  66. }
  67.  
  68. ;===Functions===========================================================================
  69. CaptureScreen(aRect)
  70. {
  71. StringSplit, rt, aRect, `,, %A_Space%%A_Tab%
  72. nL := rt1
  73. nT := rt2
  74. nW := rt3 - rt1
  75. nH := rt4 - rt2
  76. znW := rt5
  77. znH := rt6
  78.  
  79. mDC := DllCall("CreateCompatibleDC", "Uint", 0)
  80. hBM := CreateDIBSection(mDC, nW, nH)
  81. oBM := DllCall("SelectObject", "Uint", mDC, "Uint", hBM)
  82. hDC := DllCall("GetDC", "Uint", 0)
  83. DllCall("BitBlt", "Uint", mDC, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", hDC, "int", nL, "int", nT, "Uint", 0x40000000 | 0x00CC0020)
  84. DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
  85. DllCall("SelectObject", "Uint", mDC, "Uint", oBM)
  86. DllCall("DeleteDC", "Uint", mDC)
  87. SetClipboardData(hBM)
  88. }
  89.  
  90. CreateDIBSection(hDC, nW, nH, bpp = 32, ByRef pBits = "")
  91. {
  92. NumPut(VarSetCapacity(bi, 40, 0), bi)
  93. NumPut(nW, bi, 4)
  94. NumPut(nH, bi, 8)
  95. NumPut(bpp, NumPut(1, bi, 12, "UShort"), 0, "Ushort")
  96. NumPut(0, bi,16)
  97. Return DllCall("gdi32\CreateDIBSection", "Uint", hDC, "Uint", &bi, "Uint", 0, "UintP", pBits, "Uint", 0, "Uint", 0)
  98. }
  99.  
  100. SetClipboardData(hBitmap)
  101. {
  102. DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi)
  103. hDIB := DllCall("GlobalAlloc", "Uint", 2, "Uint", 40+NumGet(oi,44))
  104. pDIB := DllCall("GlobalLock", "Uint", hDIB)
  105. DllCall("RtlMoveMemory", "Uint", pDIB, "Uint", &oi+24, "Uint", 40)
  106. DllCall("RtlMoveMemory", "Uint", pDIB+40, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44))
  107. DllCall("GlobalUnlock", "Uint", hDIB)
  108. DllCall("DeleteObject", "Uint", hBitmap)
  109. DllCall("OpenClipboard", "Uint", 0)
  110. DllCall("EmptyClipboard")
  111. DllCall("SetClipboardData", "Uint", 8, "Uint", hDIB)
  112. DllCall("CloseClipboard")
  113. }
  114.  
  115.  
  116. ;===Hotkeys=============================================================================
  117. ^Lbutton:: ; Click and drag to select area to clip
  118. no++
  119. if no > 4
  120. {
  121. 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)
  122. IfMsgBox, yes
  123. {
  124. Progress, m2 b fs13 zh0 WMn700, Container emptied!
  125. Gosub, EmptyAndProgressOff
  126. Return
  127. }
  128. Else
  129. Return
  130. }
  131.  
  132. CoordMode, Mouse ,Screen
  133. MouseGetPos, MX, MY
  134. Gui, +AlwaysOnTop -caption +Border +ToolWindow +LastFound
  135. WinSet, Transparent, %SelectionTransparency%
  136. Gui, Color, %SelectionColor%
  137.  
  138. While, (GetKeyState("LButton", "p"))
  139. {
  140. MouseGetPos, MXend, MYend
  141. Send {control up}
  142. w := abs(MX - MXend)
  143. h := abs(MY - MYend)
  144. If (MX < MXend)
  145. X := MX
  146. Else
  147. X := MXend
  148. If (MY < MYend)
  149. Y := MY
  150. Else
  151. Y := MYend
  152. Gui, Show, x%X% y%Y% w%w% h%h%
  153. if (GetKeyState("c", "p")) ; Cancel while selecting area (abort)
  154. {
  155. Gui, Destroy
  156. no--
  157. Send, {control up}{c up}{LButton up}
  158. Return
  159. }
  160. Sleep, 10
  161. }
  162.  
  163. MouseGetPos, MXend, MYend
  164. if ApplyColorEffect = yes
  165. {
  166. Gui, hide
  167. Gui, -Border
  168. Gui, Show, x%X% y%Y% w%w% h%h%
  169. }
  170. if ApplyColorEffect = no
  171. Gui, Destroy
  172. If (MX > MXend)
  173. {
  174. temp := MX
  175. MX := MXend
  176. MXend := temp
  177. }
  178. If (MY > MYend)
  179. {
  180. temp := MY
  181. MY := MYend
  182. MYend := temp
  183. }
  184. Area = %MX%, %MY%, %MXend%, %MYend%
  185. OriginalClipboard = %ClipboardAll% ; save
  186. Sleep, 100 ; if omitted, GUI sometimes stays in picture
  187. CaptureScreen(Area) ; Saves selected area without cursor in Clipboard.
  188. if ApplyColorEffect = yes
  189. Gui, Destroy
  190. Picture%no% := ClipboardAll
  191. Progress, m2 b fs13 zh0 WMn700 w40, %no%
  192. Sleep, 600
  193. Clipboard = %OriginalClipboard% ; restore
  194. Progress, off
  195. Return
  196.  
  197. ^1:: ; Paste 1. picture
  198. ^2:: ; Paste 2. picture
  199. ^3:: ; Paste 3. picture
  200. ^4:: ; Paste 4. picture
  201. Gosub, PastePicture
  202. Return
  203.  
  204. ^e:: ; Empty picture container and restart numbering
  205. Progress, m2 b fs13 zh0 WMn700, Container emptied!
  206. IfWinExist, Container full!
  207. {
  208. SetControlDelay, -1
  209. ControlClick, &No, Container full!
  210. SetControlDelay, 20
  211. }
  212. Gosub, EmptyAndProgressOff
  213. Return
  214.  
  215. Escape:: ; Exit
  216. Suspend
  217. ExitApp
  218.  
  219.  
  220. ;===Subroutines=========================================================================
  221. PastePicture:
  222. OriginalClipboard = %ClipboardAll% ; save
  223. StringTrimLeft, PicNo, A_ThisHotkey, 1
  224. if PicNo = 1
  225. Clipboard := Picture1
  226. Else if PicNo = 2
  227. Clipboard := Picture2
  228. Else if PicNo = 3
  229. Clipboard := Picture3
  230. Else if PicNo = 4
  231. Clipboard := Picture4
  232. Sleep, %AppendClipboardSleep% ; if omitted, next command sometimes paste OriginalClipboard, not Picture! Use Clipboard := "" and ClipWait if you wish.
  233. Send, ^v
  234. Clipboard = %OriginalClipboard% ; restore
  235. Return
  236.  
  237. EmptyAndProgressOff:
  238. Picture1 =
  239. Picture2 =
  240. Picture3 =
  241. Picture4 =
  242. no = 0
  243. Sleep, 900
  244. Progress, off
  245. Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement