问题
This script should create an automated screen capture from a specific window even in background. The function to take a screenshot works but I have problems to put it together so I can compile and run it.
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
; Press ESC to exit script
HotKeySet("{ESC}", "On_Exit")
Global $Paused, $Runner
Global $fNot_1_Vis = True, $iBegin = 0
Global $sAutoIt_Path = StringRegExpReplace(@AutoItExe, "(^.*\\)(.*)", "\1")
_GDIPlus_Startup()
Global $handle = WinGetHandle("[HANDLE:NOTEPAD]") ; This is the Handle from the window to capture found manual under WindowInfo! ;
_GDIPlus_Shutdown() ; Shuts down the process. ;
_ScreenCapture_SetJPGQuality(100);max image quality
$scrFile = @ScriptDir & "\screenshot - " & @MDAY & @MON & @YEAR & '-' & @HOUR &@MIN& @SEC & ".png" ;save file with name format;
_ScreenCapture_CaptureWnd($scrFile, "[ACTIVE]", -1, -1, -1, -1, 0)
Opt("TrayAutoPause", 0)
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("{F9}", "Capture_Window")
Func On_Exit()
Exit
EndFunc
While 1
Sleep(100)
WEnd
;;;;;;;;
Func TogglePause()
$Paused = Not $Paused
While $Paused
Sleep(100)
ToolTip('Script is "Paused"', 0, 0)
WEnd
ToolTip("")
EndFunc ;==>TogglePause
Func Terminate()
Exit 0
EndFunc ;==>Terminate
Func Capture_Window($hWnd, $w, $h)
$Runner = Not $Runner
While $Runner
Sleep(3000)
If Int($w) < 1 Then Return SetError(2, 0, 0)
If Int($h) < 1 Then Return SetError(3, 0, 0)
Local Const $hDC_Capture = _WinAPI_GetDC(HWnd($hWnd))
Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
Local Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $w, $h)
Local Const $hObjectOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
DllCall("gdi32.dll", "int", "SetStretchBltMode", "hwnd", $hDC_Capture, "uint", 4)
DllCall("user32.dll", "int", "PrintWindow", "hwnd", $hWnd, "handle", $hMemDC, "int", 0)
_WinAPI_DeleteDC($hMemDC)
_WinAPI_SelectObject($hMemDC, $hObjectOld)
_WinAPI_ReleaseDC($hWnd, $hDC_Capture)
Local Const $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]")
Local Const $aFullScreen = WinGetPos($hFullScreen)
Local Const $c1 = $aFullScreen[2] - @DesktopWidth, $c2 = $aFullScreen[3] - @DesktopHeight
Local Const $wc1 = $w - $c1, $hc2 = $h - $c2
WEnd
EndFunc
回答1:
You want it to do a screenshot every 60 seconds, but you don't have any code to do so.
Replace your main loop
While 1
Sleep(100)
WEnd
with something like
While 1
Sleep(60*1000)
Capture_Window($handle, $w, $h)
WEnd
Of course $handle
, $w
and $h
should be set properly before. You may also want to decrease the sleep time by the approximate time, Capture_Window
needs.
回答2:
… i have problems to put the automatic shot every 60s …
Windows Task Scheduler may be used. Example using AutoIt (executes on each new minute):
#include <ScreenCapture.au3>
Global Const $g_iDelay = 10
Global Const $g_sSeconds = '00'
Global Const $g_sFileName = @ScriptDir & '\screenshot_%s.jpg'
Global Const $g_sKeyExit = '{ESC}'
Global $g_bStateExit = False
Main()
Func Main()
Local $sTimeStamp = ''
Local $sFileName = ''
HotKeySet($g_sKeyExit, 'SetStateExit')
While Not $g_bStateExit
If Not (@SEC = $g_sSeconds) Then
Sleep($g_iDelay)
ContinueLoop
EndIf
$sTimeStamp = @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC
$sFileName = StringFormat($g_sFileName, $sTimeStamp)
_ScreenCapture_Capture($sFileName)
WEnd
Exit
EndFunc
Func SetStateExit()
$g_bStateExit = True
EndFunc
Simply replace _ScreenCapture_Capture()
(since "take a Screenshot itself works").
Related.
回答3:
If you are running on Ubuntu. It is easy for that.
Install scrot and then run this:
while true; do scrot & sleep 60; done
and you will see screenshots images are stored on your current directory.
This answer is from https://askubuntu.com/questions/50958/how-to-take-a-screenshot-every-n-second?newreg=c4df0efd62be49e68edef2a9083e1342
来源:https://stackoverflow.com/questions/48847275/take-screenshot-every-60-seconds