aa2zz6

Solved - How would I save a print screen to a file with the current date.

7 posts in this topic

#1 ·  Posted (edited)

I'm writing this script for my parent who is less tech savvy. For the work she does sometimes the website gets glitched and she has to take print screens and then email. I was wondering if it was possible to have the print screen save as the current date. I've used the _NowDate for many of my projects but I wasn't able to figure it out. 

 

#include <ScreenCapture.au3>
#include<Date.au3>

HotKeySet("{PRINTSCREEN}", "printscreen")

While 1
    Sleep(100)
WEnd


Func printscreen()
    _ScreenCapture_Capture(@DesktopDir & "\picture.jpg")
EndFunc

 

Edited by aa2zz6

Share this post


Link to post
Share on other sites



You can do this. StringReplace(_NowDate(),"/","-")

 

Saludos

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hello

#include <File.au3>
#include <ScreenCapture.au3>

HotKeySet("{PRINTSCREEN}", "printscreen")

While 1
    Sleep(100)
WEnd

Func printscreen()
$FilePath =(@DesktopDir&"/")
$FileName = 'Vv'
$FileList = _FileListToArray($FilePath, $FileName & '*.jpg', 1)

If Not IsArray($FileList) Then
    $FileName&= '1.jpg'
Else
        $FileName &= $FileList[0] + 1 & '.jpg'
EndIf
_ScreenCapture_Capture($FilePath & "\" & $FileName)
EndFunc

 

Edited by ahmeddzcom

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks for the advice guys, the working code will be listed below.

#include <ScreenCapture.au3>
#include<Date.au3>
#include <MsgBoxConstants.au3>

HotKeySet("{PRINTSCREEN}", "prtSc")

Local $sString = StringReplace(_NowDate(),"/","-")

While 1
    Sleep(100)
WEnd


Func prtSc()
    _ScreenCapture_Capture(@DesktopDir & "\" & $sString & ".jpg")
EndFunc

 

Edited by aa2zz6
Revised code!

Share this post


Link to post
Share on other sites

aa2zz6,

If you wanted to include the time (multiple copies per day) you could do something like this...

#include <ScreenCapture.au3>
#include <Date.au3>
#include <MsgBoxConstants.au3>

HotKeySet("{PRINTSCREEN}", "prtSc")

Local $sString = StringReplace(_NowDate(), "/", "-")

While 1
    Sleep(100)
WEnd



Func prtSc()
    _ScreenCapture_Capture(@DesktopDir & "\" & StringRegExpReplace(_Now(), '[/ :]', '-') & ".jpg")
EndFunc   ;==>prtSc

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Thanks kylomas, I was planning to look at ahmeddzcom code tomorrow after work and see how I could go about creating multiple images. I do appreciate the help from everyone! 

Share this post


Link to post
Share on other sites

You can save also the bitmap from the clipboard:

#include <Clipboard.au3>
#include <GDIPlus.au3>

_GDIPlus_Startup()
Send("{PRINTSCREEN}")
Sleep(100)
ConsoleWrite(_GDIPlus_ImageSaveClipboardToFile(@ScriptDir & "\" & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & "_Test.jpg") & "/" & @error & @CRLF)
_GDIPlus_Shutdown()

Func _GDIPlus_ImageSaveClipboardToFile($sFilename) ;coded by UEZ build 2015-10-01
    If Not _ClipBoard_Open(0) Then Return SetError(1, 0, 0)
    Local Const $hMemoryBMP = _ClipBoard_GetDataEx($CF_BITMAP)
    If Not $hMemoryBMP Then
        _ClipBoard_Close()
        Return SetError(2, 0, 0)
    EndIf
    Local Const $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hMemoryBMP)
    _ClipBoard_Close()
    _WinAPI_DeleteObject($hMemoryBMP)
    If Not _GDIPlus_ImageSaveToFile($hBmp, $sFilename) Then
        _GDIPlus_BitmapDispose($hBmp)
        Return SetError(3, 0, 0)
    EndIf
    _GDIPlus_BitmapDispose($hBmp)
    Return 1
EndFunc

 


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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