此脚本应该从特定窗口创建自动屏幕捕获,即使在后台也是如此。截取屏幕截图的功能可行,但我将它放在一起有问题,所以我可以编译并运行它。
#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
答案 0 :(得分:0)
您希望它每60秒执行一次屏幕截图,但您没有任何代码可以执行此操作。
替换主循环
While 1
Sleep(100)
WEnd
类似
While 1
Sleep(60*1000)
Capture_Window($handle, $w, $h)
WEnd
当然$handle
,$w
和$h
之前应该正确设置。您可能还希望将睡眠时间减少大约需要Capture_Window
的时间。
答案 1 :(得分:0)
...我每60秒自动拍摄就有问题...
可以使用Windows任务计划程序。使用AutoIt的示例(在每分钟执行时):
#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
只需替换_ScreenCapture_Capture()
(因为“将截图本身设为”)。