Sign in to follow this  
Followers 0
Elephant007

[Solved] How Do I Capture Screen When New Window(s) Appear?

9 posts in this topic

#1 ·  Posted (edited)

Below is code I was able to find here and tweak to my liking, almost

The part I would like to know how to change is instead of this taking a screenshot every 10 seconds I would like for it to take a screenshot anytime a new window appears OR anytime the desktop has some sort of GUI change.

I tried adding WinWait ("","")

This just took more rapid screenshots.

The purpose of this code is to monitor the installation of a very large program. I don't want have to have to sit and wait for each window to popup and record because I plan on making the entire installation silent using AutoIt scripting ;)

#include <ScreenCapture.au3>

HotKeySet("{Esc}", "Quit")
Call("StartCapture")

Func StartCapture()

While 1
Sleep(10000)
_ScreenCapture_Capture ("C:\" & @HOUR & @MIN & @SEC & ".jpeg")
Wend
EndFunc

Func Quit ()
Exit
EndFunc

With bogQ's help I was able to find a solution for this

you can find the solution here Solution In Thread

Edited by Elephant007

Share this post


Link to post
Share on other sites



i don't think that i completely understand what are you asking

If you trying to get new active win you can try like this

While 1
    $a = WinGetTitle("")
    Do
        $b = WinGetTitle("")
    Until $a <> $b
    MsgBox(0,"","something happend")
WEnd

If you try to get new win that was not there before than i think you shud use

WinList() to get it and then compare it to new list to get new win


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

thank you for your reply.

In it's basic form this is what I want to accomplish

Start my code and let it run in a loop

Anytime a new window opens on my computers, I want the code to take a screen shot and save it as a JPEG ( using @hour & @min & @sec & ".jpeg" for the file name)

Currently my code takes a screen shot every 10 seconds. I want to change it from 10 seconds to when a (non-existing) window appears. I won't know the name of any of the windows that will appear

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This should work if im not wrong, it should react on new wins with diffrent title,

if they are with the same title try to change

_ArraySearch($var1, $var2[$x][0], 0, 0, 0, 1)

to

_ArraySearch($var1, $var2[$x][1], 0, 0, 0, 1)

and see if its working after change

#include <Array.au3>
$var1 = WinList()
While 1
    $var2 = WinList()
    For $x = 1 To $var2[0][0]
        $iIndex = _ArraySearch($var1, $var2[$x][0], 0, 0, 0, 1)
        If @error And $var2[$x][0] <> "" And IsVisible($var2[$x][1])Then
            MsgBox(0, "New Win", WinGetTitle($var2[$x][1]))
            $var1 = WinList()
        EndIf
    Next
    If $var2[0][0] <> $var1[0][0] Then
        $var1 = WinList()
    EndIf
WEnd
Func IsVisible($handle)
    If BitAnd( WinGetState($handle), 2 ) Then 
        Return 1
    Else
        Return 0
    EndIf
EndFunc

Edit: note that this script is eating up CPU

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks again for your speedy and excellent help!

The first code you provided me did the trick, I added to my existing code and it's about 3/4th complete... the only thing I feel it's lacking is adding a slight delay before the screen shot is taken... prehaps just one or two seconds..

If you're able to inform me how to add the delay, I can tweak it to my liking, here is my new code

#include <ScreenCapture.au3>

HotKeySet("{Esc}", "Quit")
Call("StartCapture")

Func StartCapture()

While 1
    $a = WinGetTitle("")
    Do
        $b = WinGetTitle("")
    Until $a <> $b
    _ScreenCapture_Capture ("C:\" & @HOUR & @MIN & @SEC & ".jpeg")
WEnd
EndFunc

Func Quit ()
Exit
EndFunc

When run, the script will capture the desktop screen when new windows appears. It saves the image to the C drive with the HOUR MINUTE SECOND .JPEG

you can press the ESC key to exit the script

Again, thank you for your excellent help...

Just need to just figure out how to delay the _ScreenCapture_Capture

Thank yoU!@

Edited by Elephant007

Share this post


Link to post
Share on other sites

Sleep(1000)

that 1000 is 1 second ;)


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Sleep(1000)

that 1000 is 1 second ;)

Where do I put that code?

Right after Until $a <> $b?

Until $a <> $b
Sleep (1000)
Edited by Elephant007

Share this post


Link to post
Share on other sites

yes


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

thanks! With you guidance I was able to complete this code!!!

I will post it here and in the first of this thread too

Q: What will this code do?

A: Oa message box with some info, click OK to start the program, CANCEL to exit from starting the program.

Once you click OK a directory will be created on your C drive called "ScreenCaptures" with a subdirecty MONTH-DAY-YEAR.

Any changes made on your desktop will be captured and saved as a JPEG in the directory created "C:\ScreenCaptures\MONTH-DAY-YEAR"

The jpeg's are saved as HOUR.MINUTE.SECOND.JPEG, this way they will be stored sequencially.

Feel free to use and change as needed

#include <ScreenCapture.au3>
$MsgBox01 = MsgBox ( 1, "ScreenCaptures", "Starting ScreenCapture" & @CRLF & "Press ESC to Quit ScreenCapture"  & @CRLF & "Images saved to C:\ScreenCaptures\" & @MON & "-" & @MDAY & "-" & @YEAR & @CRLF & "Click cancel to not run ScreenCapture" )
If $MsgBox01 = 2 Then Exit
DirCreate ( "C:\ScreenCaptures\" & @MON & "-" & @MDAY & "-" & @YEAR )

HotKeySet("{Esc}", "Quit")
Call("StartCapture")

Func StartCapture()

While 1
    $a = WinGetTitle("")
    Do
        $b = WinGetTitle("")
    Until $a <> $b
    Sleep (1000)
    _ScreenCapture_Capture ( "C:\ScreenCaptures\" & @MON & "-" & @MDAY & "-" & @YEAR & "\" & @HOUR & @MIN & @SEC & ".jpeg" )
   ; _ScreenCapture_Capture ("C:\ScreenCaptures\" & @HOUR & @MIN & @SEC & ".jpeg")
WEnd
EndFunc

Func Quit ()
    Run ( "Explorer.exe " & "C:\ScreenCaptures" )
Exit
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0