Is it possible to use printscreen to save an image Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
songdg
Posts: 557
Joined: 04 Oct 2017, 20:04

Is it possible to use printscreen to save an image

22 Apr 2019, 07:27

I want to use printscreen key to capture the screen and then save an image file.
zayntheboss
Posts: 15
Joined: 24 Feb 2019, 15:21

Re: Is it possible to use printscreen to save an image

22 Apr 2019, 09:03

Here's a script I wrote that does just that

Code: Select all

^q::
sleep, 100
send {PrintScreen}
sleep, 500
run MSPaint
Sleep, 1000
Send, #{Up}
Sleep, 500
Mouseclick, left, 250, 250, 5
Sleep, 200
send ^v
sleep, 500
Send ^s
Random, filename, 10000, 99999
Sleep, 500
Send %filename%
Sleep, 500
Send ^l
Sleep, 200
Send, desktop
Loop, 5 {
Send, {enter}
Sleep, 300
}
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: Is it possible to use printscreen to save an image  Topic is solved

22 Apr 2019, 09:12

I use Gdip.ahk by tic to save the screenshot as file.
btw, you can use other Hotkey, not just PrintScreen

Code: Select all

#Include Gdip.ahk

PrintScreen::
    CurrentDate := A_YYYY "-" A_MM "-" A_DD
    CurrentTime := A_Hour "-" A_Min "-" A_Sec "." A_MSec

    Screenshot(CurrentDate "_" CurrentTime ".png")
Return

Screenshot(OutFile)
{
    pToken := Gdip_Startup()

    screen=0|0|%A_ScreenWidth%|%A_ScreenHeight%
    pBitmap := Gdip_BitmapFromScreen(screen)

    Gdip_SaveBitmapToFile(pBitmap, OutFile, 100)
    Gdip_DisposeImage(pBitmap)
    Gdip_Shutdown(pToken)
}
Here is the link:
https://github.com/tariqporter/Gdip/
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6517
songdg
Posts: 557
Joined: 04 Oct 2017, 20:04

Re: Is it possible to use printscreen to save an image

26 Apr 2019, 01:42

zayntheboss wrote:
22 Apr 2019, 09:03
Here's a script I wrote that does just that

Code: Select all

^q::
sleep, 100
send {PrintScreen}
sleep, 500
run MSPaint
Sleep, 1000
Send, #{Up}
Sleep, 500
Mouseclick, left, 250, 250, 5
Sleep, 200
send ^v
sleep, 500
Send ^s
Random, filename, 10000, 99999
Sleep, 500
Send %filename%
Sleep, 500
Send ^l
Sleep, 200
Send, desktop
Loop, 5 {
Send, {enter}
Sleep, 300
}
Thank you very much.
songdg
Posts: 557
Joined: 04 Oct 2017, 20:04

Re: Is it possible to use printscreen to save an image

26 Apr 2019, 01:44

Ridwan wrote:
22 Apr 2019, 09:12
I use Gdip.ahk by tic to save the screenshot as file.
btw, you can use other Hotkey, not just PrintScreen

Code: Select all

#Include Gdip.ahk

PrintScreen::
    CurrentDate := A_YYYY "-" A_MM "-" A_DD
    CurrentTime := A_Hour "-" A_Min "-" A_Sec "." A_MSec

    Screenshot(CurrentDate "_" CurrentTime ".png")
Return

Screenshot(OutFile)
{
    pToken := Gdip_Startup()

    screen=0|0|%A_ScreenWidth%|%A_ScreenHeight%
    pBitmap := Gdip_BitmapFromScreen(screen)

    Gdip_SaveBitmapToFile(pBitmap, OutFile, 100)
    Gdip_DisposeImage(pBitmap)
    Gdip_Shutdown(pToken)
}
Here is the link:
https://github.com/tariqporter/Gdip/
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6517
Thanks for your direction.
songdg
Posts: 557
Joined: 04 Oct 2017, 20:04

Re: Is it possible to use printscreen to save an image

13 Jun 2019, 20:38

If I want to use Gdip.ahk to select a rectangle area of the screen manually and save it as an image, how to do that, thanks.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Is it possible to use printscreen to save an image

13 Jun 2019, 20:49

songdg wrote:
13 Jun 2019, 20:38
If I want to use Gdip.ahk to select a rectangle area of the screen manually and save it as an image, how to do that, thanks.
I just posted a script here that has that written into it.


https://www.autohotkey.com/boards/viewtopic.php?f=6&t=60949

It only draws on the main monitor, but can be tweaked to work on any monitor, in fact, I just wrote a class yesterday that I intend to use for these tasks.
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=65366


There are a few functions in that first script that use my own custom gdip functions. They can be found in the lower part of the script.

If you need help picking out the code let me know.

Good luck.
songdg
Posts: 557
Joined: 04 Oct 2017, 20:04

Re: Is it possible to use printscreen to save an image

17 Jun 2019, 01:57

Hellbent wrote:
13 Jun 2019, 20:49
songdg wrote:
13 Jun 2019, 20:38
If I want to use Gdip.ahk to select a rectangle area of the screen manually and save it as an image, how to do that, thanks.
I just posted a script here that has that written into it.


https://www.autohotkey.com/boards/viewtopic.php?f=6&t=60949

It only draws on the main monitor, but can be tweaked to work on any monitor, in fact, I just wrote a class yesterday that I intend to use for these tasks.
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=65366


There are a few functions in that first script that use my own custom gdip functions. They can be found in the lower part of the script.

If you need help picking out the code let me know.

Good luck.
Thanks for your help, your scrip is a bit complex for a newbie like me.
Use that function?
Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h){
Ptr := A_PtrSize ? "UPtr" : "UInt"
return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
}
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Is it possible to use printscreen to save an image

17 Jun 2019, 02:17

songdg wrote:
17 Jun 2019, 01:57
Thanks for your help, your scrip is a bit complex for a newbie like me.
Use that function?
Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h){
Ptr := A_PtrSize ? "UPtr" : "UInt"
return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
}
Yes that function is what you use to draw your rectangle.

The other day I took the scripts I linked you to and created a little script that does a image search. It might be helpful to you.
Once again it is a bit complex but it has drawing a rectangle, taking a screenshot, setting a search area and running a search.

https://www.autohotkey.com/boards/viewtopic.php?f=76&t=65438

A few months ago someone had asked me how to draw a rectangle to their screen so I made a little video that covers it step by step.
If you find the script in the thread I posted to complex, this should make things easy for you.

https://www.youtube.com/watch?v=80FhzIm9IQQ

Let me know how it works out for you.
DonTutti
Posts: 5
Joined: 23 May 2019, 15:21

Re: Is it possible to use printscreen to save an image

17 Jun 2019, 03:21

Hello, is it possible to change mouse cursor to square about 10x10 pixels and take screenshot when I click mouse buton in mouse position?
i5aeid
Posts: 2
Joined: 04 May 2021, 16:53

Re: Is it possible to use printscreen to save an image

04 May 2021, 17:27

Ridwan wrote:
22 Apr 2019, 09:12
I use Gdip.ahk by tic to save the screenshot as file.
btw, you can use other Hotkey, not just PrintScreen

Code: Select all

#Include Gdip.ahk

PrintScreen::
    CurrentDate := A_YYYY "-" A_MM "-" A_DD
    CurrentTime := A_Hour "-" A_Min "-" A_Sec "." A_MSec

    Screenshot(CurrentDate "_" CurrentTime ".png")
Return

Screenshot(OutFile)
{
    pToken := Gdip_Startup()

    screen=0|0|%A_ScreenWidth%|%A_ScreenHeight%
    pBitmap := Gdip_BitmapFromScreen(screen)

    Gdip_SaveBitmapToFile(pBitmap, OutFile, 100)
    Gdip_DisposeImage(pBitmap)
    Gdip_Shutdown(pToken)
}
Here is the link:
https://github.com/tariqporter/Gdip/
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6517
I just discovered this software a few hours ago and I don't know any coding, but as I reviewed the tutorials a bit, I guess there's a much easier way to do so:

Code: Select all

PrintScreen::
Send, #{PrintScreen}
In fact because by default, WindowsKey+PrintScreen automatically takes and saves a screenshot in a .png format to like C:\Users\Pictures...
I myself prefer to go with something handier like Alt+Space:

Code: Select all

!Space::
Send, #{PrintScreen}
Best,
BOLTGG
Posts: 1
Joined: 06 Jan 2022, 12:06

Re: Is it possible to use printscreen to save an image

06 Jan 2022, 12:16

Ridwan wrote:
22 Apr 2019, 09:12
I use Gdip.ahk by tic to save the screenshot as file.
btw, you can use other Hotkey, not just PrintScreen

Code: Select all

#Include Gdip.ahk

PrintScreen::
    CurrentDate := A_YYYY "-" A_MM "-" A_DD
    CurrentTime := A_Hour "-" A_Min "-" A_Sec "." A_MSec

    Screenshot(CurrentDate "_" CurrentTime ".png")
Return

Screenshot(OutFile)
{
    pToken := Gdip_Startup()

    screen=0|0|%A_ScreenWidth%|%A_ScreenHeight%
    pBitmap := Gdip_BitmapFromScreen(screen)

    Gdip_SaveBitmapToFile(pBitmap, OutFile, 100)
    Gdip_DisposeImage(pBitmap)
    Gdip_Shutdown(pToken)
}
Here is the link:
https://github.com/tariqporter/Gdip/
viewtopic.php?f=6&t=6517
I am new to ahk so i don't that much of it want to change the place where it saves the .png how do i do that
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Is it possible to use printscreen to save an image

06 Jan 2022, 13:19

BOLTGG wrote: I am new to ahk so i don't that much of it want to change the place where it saves the .png how do i do that
Like this for an absolute path:

Code: Select all

Screenshot("C:\PathToMyFile\" CurrentDate "_" CurrentTime ".png")

You can also use relative paths. This would place it in a folder named "Images" inside the script's working directory:

Code: Select all

Screenshot("Images\" CurrentDate "_" CurrentTime ".png")

In both cases, make sure the folder exists.
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Is it possible to use printscreen to save an image

08 Feb 2022, 11:20

boiler wrote:
06 Jan 2022, 13:19
Like this for an absolute path:

Code: Select all

Screenshot("C:\PathToMyFile\" CurrentDate "_" CurrentTime ".png")
Where was it saving and doesn't matter where I place this in the script?
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Is it possible to use printscreen to save an image

08 Feb 2022, 12:54

LAPIII wrote:
boiler wrote: Like this for an absolute path:

Code: Select all

Screenshot("C:\PathToMyFile\" CurrentDate "_" CurrentTime ".png")
Where was it saving and doesn't matter where I place this in the script?
It saves it wherever you define the path. You have to replace "C:\PathToMyFile\" with the path to where you want the files saved on your drive. It doesn't matter where you place the script on your drive if you specify the full path for where to save the screenshots.
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Is it possible to use printscreen to save an image

08 Feb 2022, 17:28

@boiler, why doesn't this save the screenshot and can I prevent it from copying to the clipboard? (I only edited lines are 1 and 7):

Code: Select all

#Include C:\Users\LPIII\Documents\AutoHotkey\Lib\GDIP_All.ahk

^PrintScreen::
    CurrentDate := A_YYYY "-" A_MM "-" A_DD
    CurrentTime := A_Hour "-" A_Min "-" A_Sec "." A_MSec

    Screenshot("C:\Users\LPIII\Pictures" CurrentDate "_" CurrentTime ".png")
Return

Screenshot(OutFile)
{
    pToken := Gdip_Startup()

    screen=0|0|%A_ScreenWidth%|%A_ScreenHeight%
    pBitmap := Gdip_BitmapFromScreen(screen)

    Gdip_SaveBitmapToFile(pBitmap, OutFile, 100)
    Gdip_DisposeImage(pBitmap)
    Gdip_Shutdown(pToken)
}
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Is it possible to use printscreen to save an image

08 Feb 2022, 20:02

You removed the backslash that would separate the folder name from the start of the file name. You have:

Code: Select all

    Screenshot("C:\Users\LPIII\Pictures" CurrentDate "_" CurrentTime ".png")
It needs to be:

Code: Select all

    Screenshot("C:\Users\LPIII\Pictures\" CurrentDate "_" CurrentTime ".png")

What you have would produce the path C:\Users\LPIII\Pictures2022-02-08_19-58-25.083.png
...instead of: C:\Users\LPIII\Pictures\2022-02-08_19-58-25.083.png

So if you look in your folder named C:\Users\LPIII, you probably have generated a bunch of files that have names similar to: Pictures2022-02-08_19-58-25.083.png
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Is it possible to use printscreen to save an image

05 Apr 2022, 13:49

@boiler How can I also save with the active window title?

Code: Select all

^PrintScreen::
    CurrentDate := A_YYYY "-" A_MM "-" A_DD
    CurrentTime := A_Hour "-" A_Min "-" A_Sec "." A_MSec

   Screenshot("C:\Users\LPIII\Pictures\" CurrentDate "_" CurrentTime ".png")
Return
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Is it possible to use printscreen to save an image

05 Apr 2022, 13:54

Code: Select all

^PrintScreen::
    CurrentDate := A_YYYY "-" A_MM "-" A_DD
    CurrentTime := A_Hour "-" A_Min "-" A_Sec "." A_MSec
    WinGetActiveTitle, Title
    
    Screenshot("C:\Users\LPIII\Pictures\" Title "_" CurrentDate "_" CurrentTime ".png")
Return
Caution: The title could contain unallowable file name characters, so you may want to clean it up first.
garry
Posts: 3758
Joined: 22 Dec 2013, 12:50

Re: Is it possible to use printscreen to save an image

05 Apr 2022, 14:25

boiler wrote :
Caution: The title could contain unallowable file name characters, so you may want to clean it up first.
yes, example to remove all not allowed characters :

Code: Select all

transform,s,chr,34
title:="    This is : a test < see here \  /   |  ?   > " . s . " title   你好  " . s . "    END      "
msgbox,OLDTITLE="%title%"   
newStr  := RegExReplace(title, "[<>:""/\\|?*]")
NewTitle:=RegExReplace(newstr,"\x20{2,}"," ")     ;- keep only one space
newtitle=%newtitle%
msgbox,NEWTITLE="%newtitle%"
;-
;-- remove in Title if used for Fileappend :
/*
Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:
The following reserved characters:
https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
< (less than)
> (greater than)
: (colon)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)
*/

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: dipahk, Google [Bot] and 244 guests