Advertisement
dangerdogL2121

Screen Capturer (main code not mine)

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