每隔60秒拍摄一次屏幕截图

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了每隔60秒拍摄一次屏幕截图相关的知识,希望对你有一定的参考价值。

此脚本应该甚至在后台从特定窗口创建自动屏幕捕获。截取屏幕截图的功能可行,但我把它放在一起有问题,所以我可以编译并运行它。

#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
答案

您希望它每隔60秒进行一次屏幕截图,但您没有任何代码可以执行此操作。

更换主循环

While 1
    Sleep(100)
WEnd

喜欢的东西

While 1
    Sleep(60*1000)
    Capture_Window($handle, $w, $h)
WEnd

当然$handle$w$h之前应该正确设置。您可能还希望通过Capture_Window需要的大致时间来减少睡眠时间。

另一答案

...我有问题每隔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()(因为“采取截图本身工作”)。

Related

以上是关于每隔60秒拍摄一次屏幕截图的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript定时器案例:显示年月日时分秒+每隔60s发送一次短信

python定时器每隔几秒执行一次

在 iPhone 中每 60 秒调用一次方法

当应用程序处于横向模式时拍摄屏幕截图

Android:FusedLocationProvider,每隔几秒获取一次位置

拍摄 UIWebView 的快照/屏幕截图