Advertisement
dangerdogL2121

Finished Screen Capturer!

Jun 4th, 2013
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance,Force
  2. SetTitleMatchMode,2
  3. AutoTrim,Off
  4. SetBatchLines,-1
  5. count=1
  6. /*
  7. Original code by sean.
  8. Forum post with original http://www.autohotkey.com/board/topic/16677-screen-capture-with-transparent-windows-and-mouse-cursor/page-1
  9. Note:Sean's link doesn't work for me.  If it doesn't work for you, go to the bottom post at
  10. http://www.autohotkey.com/board/topic/16677-screen-capture-with-transparent-windows-and-mouse-cursor/page-14
  11. by datalife.
  12.  
  13. Edited by dangerdogL2121
  14. You will need the program at http://en.cze.cz/Images-to-video
  15. Put it in the same folder as this script.
  16. Have fun!
  17. */
  18. ;loop 10 ;Area of screen
  19. ;CaptureScreen("100, 100, 400, 400",, A_ScriptDir "\CaptureAreaOfScreen" a_index ".jpg")
  20. ;
  21. ;loop 10 ;Entire Screen
  22. ;CaptureScreen(,,A_ScriptDir "\CaptureEntireScreen" a_index ".jpg")
  23. ;
  24. ;loop 10 ;Active window
  25. ;CaptureScreen(1, false, A_ScriptDir "\CaptureActiveScreen" a_index ".jpg")
  26. ;return
  27. ;
  28. OnExit, endprogram
  29.  
  30. FileRemoveDir,%A_Desktop%\ScreenPictures,1
  31. FileCreateDir,%A_Desktop%\ScreenPictures
  32. FileSetAttrib,-H,%A_Desktop%\ScreenPictures\ScreenCapture
  33. Gui, Font, s16 CRed w400, Arial Bold
  34. Gui,Add,Text,+wrap w900,The program will take screen captures and then put them in a folder called ScreenPictures in the desktop.  The program will then run another program to turn the screen captures into a video.`nThe program won't start taking screen captures until this window is fully closed; 0.3 seconds after you click YES.`nAfter the screen capturing has ended, the program will pull up a window of ScreenPictures.`nPress CTRL+X to stop the picture capture.`nClick YES to run the program and NO to exit the program.
  35. Gui,Add,Button,Default grun,Start screen captures
  36. Gui,Add,Button,Default gend,Exit program
  37. Gui,show,Center
  38. return
  39.  
  40. end:
  41. ExitApp
  42. return
  43.  
  44. run:
  45. Gui,Destroy
  46. Hotkey,^x,end,On
  47. sleep,300
  48. SetTimer, capture,1
  49. begtick=%A_TickCount%
  50. return
  51.  
  52.  
  53. capture:
  54. {
  55. CaptureScreen(, True,A_Desktop "\ScreenPictures\ScreenCapture" count ".jpg")
  56. count++
  57. }
  58. if count = 200000
  59. {
  60. msgbox,You have reached the limit of 200,000 of screen captures.
  61. ExitApp
  62. }
  63. return
  64.  
  65. CaptureScreen(aRect = 0, bCursor = False, sFile = "", nQuality = "")
  66. {
  67.     If    !aRect
  68.     {
  69.         SysGet, nL, 76  ; virtual screen left & top
  70.         SysGet, nT, 77
  71.         SysGet, nW, 78    ; virtual screen width and height
  72.         SysGet, nH, 79
  73.     }
  74.     Else If    aRect = 1
  75.         WinGetPos, nL, nT, nW, nH, A
  76.     Else If    aRect = 2
  77.     {
  78.         WinGet, hWnd, ID, A
  79.         VarSetCapacity(rt, 16, 0)
  80.         DllCall("GetClientRect" , "Uint", hWnd, "Uint", &rt)
  81.         DllCall("ClientToScreen", "Uint", hWnd, "Uint", &rt)
  82.         nL := NumGet(rt, 0, "int")
  83.         nT := NumGet(rt, 4, "int")
  84.         nW := NumGet(rt, 8)
  85.         nH := NumGet(rt,12)
  86.     }
  87.     Else If    aRect = 3
  88.     {
  89.         VarSetCapacity(mi, 40, 0)
  90.         DllCall("GetCursorPos", "int64P", pt)
  91.         DllCall("GetMonitorInfo", "Uint", DllCall("MonitorFromPoint", "int64", pt, "Uint", 2), "Uint", NumPut(40,mi)-4)
  92.         nL := NumGet(mi, 4, "int")
  93.         nT := NumGet(mi, 8, "int")
  94.         nW := NumGet(mi,12, "int") - nL
  95.         nH := NumGet(mi,16, "int") - nT
  96.     }
  97.     Else
  98.     {
  99.         StringSplit, rt, aRect, `,, %A_Space%%A_Tab%
  100.         nL := rt1    ; convert the Left,top, right, bottom into left, top, width, height
  101.         nT := rt2
  102.         nW := rt3 - rt1
  103.         nH := rt4 - rt2
  104.         znW := rt5
  105.         znH := rt6
  106.     }
  107.  
  108.     mDC := DllCall("CreateCompatibleDC", "Uint", 0)
  109.     hBM := CreateDIBSectionForScreenCapture(mDC, nW, nH)
  110.     oBM := DllCall("SelectObject", "Uint", mDC, "Uint", hBM)
  111.     hDC := DllCall("GetDC", "Uint", 0)
  112.     DllCall("BitBlt", "Uint", mDC, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", hDC, "int", nL, "int", nT, "Uint", 0x40000000 | 0x00CC0020)
  113.     DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
  114.     If    bCursor
  115.         CaptureCursor(mDC, nL, nT)
  116.     DllCall("SelectObject", "Uint", mDC, "Uint", oBM)
  117.     DllCall("DeleteDC", "Uint", mDC)
  118.     If    znW && znH
  119.         hBM := Zoomer(hBM, nW, nH, znW, znH)
  120.     If    sFile = 0
  121.         SetClipboardData(hBM)
  122.     Else    Convert(hBM, sFile, nQuality), DllCall("DeleteObject", "Uint", hBM)
  123. }
  124.  
  125. CaptureCursor(hDC, nL, nT)
  126. {
  127.     VarSetCapacity(mi, 20, 0), mi := Chr(20)
  128.     DllCall("GetCursorInfo", "Uint", &mi)
  129.     bShow   := NumGet(mi, 4)
  130.     hCursor := NumGet(mi, 8)
  131.     xCursor := NumGet(mi,12)
  132.     yCursor := NumGet(mi,16)
  133.  
  134.     If    bShow && hCursor:=DllCall("CopyIcon", "Uint", hCursor)
  135.     {
  136.     VarSetCapacity(ni, 20, 0)
  137.     DllCall("GetIconInfo", "Uint", hCursor, "Uint", &ni)
  138.     bIcon    := NumGet(ni, 0)
  139.     xHotspot := NumGet(ni, 4)
  140.     yHotspot := NumGet(ni, 8)
  141.     hBMMask  := NumGet(ni,12)
  142.     hBMColor := NumGet(ni,16)
  143.  
  144.     DllCall("DrawIcon", "Uint", hDC, "int", xCursor - xHotspot - nL, "int", yCursor - yHotspot - nT, "Uint", hCursor)
  145.     DllCall("DestroyIcon", "Uint", hCursor)
  146.     If    hBMMask
  147.     DllCall("DeleteObject", "Uint", hBMMask)
  148.     If    hBMColor
  149.     DllCall("DeleteObject", "Uint", hBMColor)
  150.     }
  151. }
  152.  
  153. Zoomer(hBM, nW, nH, znW, znH)
  154. {
  155.     mDC1 := DllCall("CreateCompatibleDC", "Uint", 0)
  156.     mDC2 := DllCall("CreateCompatibleDC", "Uint", 0)
  157.     zhBM := CreateDIBSectionForScreenCapture(mDC2, znW, znH)
  158.     oBM1 := DllCall("SelectObject", "Uint", mDC1, "Uint",  hBM)
  159.     oBM2 := DllCall("SelectObject", "Uint", mDC2, "Uint", zhBM)
  160.     DllCall("SetStretchBltMode", "Uint", mDC2, "int", 4)
  161.     DllCall("StretchBlt", "Uint", mDC2, "int", 0, "int", 0, "int", znW, "int", znH, "Uint", mDC1, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", 0x00CC0020)
  162.     DllCall("SelectObject", "Uint", mDC1, "Uint", oBM1)
  163.     DllCall("SelectObject", "Uint", mDC2, "Uint", oBM2)
  164.     DllCall("DeleteDC", "Uint", mDC1)
  165.     DllCall("DeleteDC", "Uint", mDC2)
  166.     DllCall("DeleteObject", "Uint", hBM)
  167.     Return    zhBM
  168. }
  169.  
  170. Convert(sFileFr = "", sFileTo = "", nQuality = "")
  171. {
  172.     If    sFileTo  =
  173.         sFileTo := A_ScriptDir . "\screen.bmp"
  174.     SplitPath, sFileTo, , sDirTo, sExtTo, sNameTo
  175.  
  176.     If Not    hGdiPlus := DllCall("LoadLibrary", "str", "gdiplus.dll")
  177.         Return    sFileFr+0 ? SaveHBITMAPToFile(sFileFr, sDirTo . "\" . sNameTo . ".bmp") : ""
  178.     VarSetCapacity(si, 16, 0), si := Chr(1)
  179.     DllCall("gdiplus\GdiplusStartup", "UintP", pToken, "Uint", &si, "Uint", 0)
  180.  
  181.     If    !sFileFr
  182.     {
  183.         DllCall("OpenClipboard", "Uint", 0)
  184.         If     DllCall("IsClipboardFormatAvailable", "Uint", 2) && (hBM:=DllCall("GetClipboardData", "Uint", 2))
  185.         DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Uint", hBM, "Uint", 0, "UintP", pImage)
  186.         DllCall("CloseClipboard")
  187.     }
  188.     Else If    sFileFr Is Integer
  189.         DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Uint", sFileFr, "Uint", 0, "UintP", pImage)
  190.     Else    DllCall("gdiplus\GdipLoadImageFromFile", "Uint", Unicode4Ansi(wFileFr,sFileFr), "UintP", pImage)
  191.  
  192.     DllCall("gdiplus\GdipGetImageEncodersSize", "UintP", nCount, "UintP", nSize)
  193.     VarSetCapacity(ci,nSize,0)
  194.     DllCall("gdiplus\GdipGetImageEncoders", "Uint", nCount, "Uint", nSize, "Uint", &ci)
  195.     Loop, %    nCount
  196.         If    InStr(Ansi4Unicode(NumGet(ci,76*(A_Index-1)+44)), "." . sExtTo)
  197.         {
  198.             pCodec := &ci+76*(A_Index-1)
  199.             Break
  200.         }
  201.     If    InStr(".JPG.JPEG.JPE.JFIF", "." . sExtTo) && nQuality<>"" && pImage && pCodec
  202.     {
  203.     DllCall("gdiplus\GdipGetEncoderParameterListSize", "Uint", pImage, "Uint", pCodec, "UintP", nSize)
  204.     VarSetCapacity(pi,nSize,0)
  205.     DllCall("gdiplus\GdipGetEncoderParameterList", "Uint", pImage, "Uint", pCodec, "Uint", nSize, "Uint", &pi)
  206.     Loop, %    NumGet(pi)
  207.         If    NumGet(pi,28*(A_Index-1)+20)=1 && NumGet(pi,28*(A_Index-1)+24)=6
  208.         {
  209.             pParam := &pi+28*(A_Index-1)
  210.             NumPut(nQuality,NumGet(NumPut(4,NumPut(1,pParam+0)+20)))
  211.             Break
  212.         }
  213.     }
  214.  
  215.     If    pImage
  216.         pCodec    ? DllCall("gdiplus\GdipSaveImageToFile", "Uint", pImage, "Uint", Unicode4Ansi(wFileTo,sFileTo), "Uint", pCodec, "Uint", pParam) : DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "Uint", pImage, "UintP", hBitmap, "Uint", 0) . SetClipboardData(hBitmap), DllCall("gdiplus\GdipDisposeImage", "Uint", pImage)
  217.  
  218.     DllCall("gdiplus\GdiplusShutdown" , "Uint", pToken)
  219.     DllCall("FreeLibrary", "Uint", hGdiPlus)
  220. }
  221.  
  222. CreateDIBSectionForScreenCapture(hDC, nW, nH, bpp = 32, ByRef pBits = "")
  223. {
  224.     NumPut(VarSetCapacity(bi, 40, 0), bi)
  225.     NumPut(nW, bi, 4)
  226.     NumPut(nH, bi, 8)
  227.     NumPut(bpp, NumPut(1, bi, 12, "UShort"), 0, "Ushort")
  228.     NumPut(0,  bi,16)
  229.     Return    DllCall("gdi32\CreateDIBSection", "Uint", hDC, "Uint", &bi, "Uint", 0, "UintP", pBits, "Uint", 0, "Uint", 0)
  230. }
  231.  
  232. SaveHBITMAPToFile(hBitmap, sFile)
  233. {
  234.     DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi)
  235.     hFile:=    DllCall("CreateFile", "Uint", &sFile, "Uint", 0x40000000, "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 0, "Uint", 0)
  236.     DllCall("WriteFile", "Uint", hFile, "int64P", 0x4D42|14+40+NumGet(oi,44)<<16, "Uint", 6, "UintP", 0, "Uint", 0)
  237.     DllCall("WriteFile", "Uint", hFile, "int64P", 54<<32, "Uint", 8, "UintP", 0, "Uint", 0)
  238.     DllCall("WriteFile", "Uint", hFile, "Uint", &oi+24, "Uint", 40, "UintP", 0, "Uint", 0)
  239.     DllCall("WriteFile", "Uint", hFile, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44), "UintP", 0, "Uint", 0)
  240.     DllCall("CloseHandle", "Uint", hFile)
  241. }
  242.  
  243. SetClipboardData(hBitmap)
  244. {
  245.     DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi)
  246.     hDIB :=    DllCall("GlobalAlloc", "Uint", 2, "Uint", 40+NumGet(oi,44))
  247.     pDIB :=    DllCall("GlobalLock", "Uint", hDIB)
  248.     DllCall("RtlMoveMemory", "Uint", pDIB, "Uint", &oi+24, "Uint", 40)
  249.     DllCall("RtlMoveMemory", "Uint", pDIB+40, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44))
  250.     DllCall("GlobalUnlock", "Uint", hDIB)
  251.     DllCall("DeleteObject", "Uint", hBitmap)
  252.     DllCall("OpenClipboard", "Uint", 0)
  253.     DllCall("EmptyClipboard")
  254.     DllCall("SetClipboardData", "Uint", 8, "Uint", hDIB)
  255.     DllCall("CloseClipboard")
  256. }
  257.  
  258. Unicode4Ansi(ByRef wString, sString)
  259. {
  260.     nSize := DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", 0, "int", 0)
  261.     VarSetCapacity(wString, nSize * 2)
  262.     DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", &wString, "int", nSize)
  263.     Return    &wString
  264. }
  265.  
  266. Ansi4Unicode(pString)
  267. {
  268.     nSize := DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "Uint", 0, "int",  0, "Uint", 0, "Uint", 0)
  269.     VarSetCapacity(sString, nSize)
  270.     DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "str", sString, "int", nSize, "Uint", 0, "Uint", 0)
  271.     Return    sString
  272. }
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280. endprogram:
  281. ticknum=%A_TickCount%
  282. tickshow=%A_TickCount%
  283. SetTimer, capture,Off
  284. Hotkey,^x,end,Off
  285. WinClose,Images To Video
  286. prevcount=%count%
  287. EnvMult, ticknum, 1000
  288. EnvMult, tickshow, 1000
  289. tickshow1=%tickshow%.00001
  290. tickshow=%tickshow1%
  291. EnvMult, begtick, 1000
  292. EnvSub, tickshow, %begtick%
  293. EnvDiv, tickshow, 1000000
  294. StringSplit, tickshowsplit, tickshow,.
  295. stringlen,tickshowlen,tickshowsplit2
  296. EnvSub, tickshowlen, 2
  297. StringTrimRight, tickshowend, tickshowsplit2, %tickshowlen%
  298. tickshow=%tickshowsplit1%.%tickshowend%
  299. EnvSub, ticknum, %begtick%
  300. EnvMult, count, 1000000
  301. count1=%count%.0000001
  302. count=%count1%
  303. EnvDiv, count, %ticknum%
  304. StringSplit, countsplit, count,.
  305. stringlen,countlen,countsplit2
  306. EnvSub, countlen, 2
  307. StringTrimRight, count1, countsplit2, %countlen%
  308. count=%countsplit1%.%count1%
  309. countround=%countsplit1%
  310. rounder=%count1%
  311. StringSplit, roundersplit, rounder
  312. if roundersplit1 > 4
  313. countround++
  314. Run, %A_Desktop%\ScreenPictures
  315. Run, %A_ScriptDir%\ImagesToVideo\ImagesToVideo.exe
  316. WinWaitActive,Images To Video
  317. Gui,+AlwaysOnTop
  318. Gui, Font, s16 CRed w400, Arial Bold
  319. Gui,add,Text,,Number of Pictures: %prevcount%`nLength of picture capture: %tickshow% seconds`nThe program took %count% pictures per second so set the the frame rate at %countround%.
  320. Gui,add,Button,Default gender,Exit screen capture program
  321. Gui,show,x0 Center
  322. return
  323.  
  324.  
  325. ender:
  326. OnExit,ender
  327. ExitApp
  328. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement