Jump to content

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


 Share

Recommended Posts

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
Link to comment
Share on other sites

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!
Link to comment
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

Link to comment
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...