Take a Screenshot by click on AHK script | Print Screen with AHK | {PrintScreen} Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
alf2314
Posts: 56
Joined: 05 Sep 2022, 13:29

Take a Screenshot by click on AHK script | Print Screen with AHK | {PrintScreen}

Post by alf2314 » 11 Sep 2022, 17:21

Greetings AHK. :thumbup:

Can you please help

is it possible to take a ScreenShot without using keys and shortcuts, only by AHK script? Similar like you just open any file
so to say, that a s cript is a stand-alone program with 1 function

I searched in the web,
but the majority of topics about {PrintScreen} are about re-mapping the keyboard shortcut,
like this

Code: Select all

F11:: Send {PrintScreen}
or this

Code: Select all

Space::Send <#{PrintScreen}
by saying "without shortcuts" I meant that a Screenshot is taken just when yuo click on script.ahk file (on your desktop, for example)
I bet there should be just a command for PrintScreen.

I suggest I shoud use

Code: Select all

Run, Target
parameter, and get smth like this

Code: Select all

Run ::{20d04fe0-3aea-1069-a2d8-08002b30309d}
but I failed to find the CLSID for PrintScreen (not sure now if it even exists)


The required behaviour is similar to this (by @teadrinker
(this script opens Windows10 calendar just by opening the ".ahk file)

Code: Select all

ControlGet, hClock, hwnd,, TrayClockWClass1, ahk_class Shell_TrayWnd
accClock := AccObjectFromWindow(hClock, OBJID_CLIENT := 0xFFFFFFFC)
accClock.accDoDefaultAction(0)

AccObjectFromWindow(hWnd, idObject = 0) {
   static IID_IDispatch   := "{00020400-0000-0000-C000-000000000046}"
        , IID_IAccessible := "{618736E0-3C3D-11CF-810C-00AA00389B71}"
        , OBJID_NATIVEOM  := 0xFFFFFFF0, VT_DISPATCH := 9, F_OWNVALUE := 1
        , h := DllCall("LoadLibrary", "Str", "oleacc", "Ptr")
        
   VarSetCapacity(IID, 16), idObject &= 0xFFFFFFFF
   DllCall("ole32\CLSIDFromString", "Str", idObject = OBJID_NATIVEOM ? IID_IDispatch : IID_IAccessible, "Ptr", &IID)
   if DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject, "Ptr", &IID, "PtrP", pAcc) = 0
      Return ComObject(VT_DISPATCH, pAcc, F_OWNVALUE)
}
Please share any idea :thumbup:
thanks

User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Take a Screenshot by click on AHK script | Print Screen with AHK | {PrintScreen}

Post by mikeyww » 12 Sep 2022, 06:09

If you remove the hotkey name itself from your first script, then the command will run when the script is run, because it will be in the auto-execute section.

https://www.autohotkey.com/docs/Scripts.htm#auto

alf2314
Posts: 56
Joined: 05 Sep 2022, 13:29

Re: Take a Screenshot by click on AHK script | Print Screen with AHK | {PrintScreen}

Post by alf2314 » 12 Sep 2022, 12:31

Hi there

I found a work-around solution, not the 100% what I wanted, but at least I achieved the desired behavior - to run it just by click on a file, without using any Shortcut and ther is no AHK green indicator in tray area.

The solution is this simple code

Code: Select all

 
Send :: #{PrintScreen}
so now the PrintScreen is taken without need to press any keys, just by click on a file.
This is useful for example if you need to pin it on the Taskbar and take a Screenshot by mouse click, whithout need to get your fingers on the keyboard (this micro-moves discomfort is the main idea Thinkpads and LAtitude still have Trackpoint - for no need to get palms off the keyboard while working, the same idea ere but in reverse)

The script can be converted into .exe and thus may serve as a stand-alone program.
You may also create a link to this file and pick a custom icon for it.

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Take a Screenshot by click on AHK script | Print Screen with AHK | {PrintScreen}

Post by flyingDman » 12 Sep 2022, 13:28

This is not a work-around solution and also not correct. As @mikeyww said, remove the hotkey label. What is left is

Code: Select all

Send, {PrintScreen}
14.3 & 1.3.7

alf2314
Posts: 56
Joined: 05 Sep 2022, 13:29

Re: Take a Screenshot by click on AHK script | Print Screen with AHK | {PrintScreen}

Post by alf2314 » 12 Sep 2022, 17:09

flyingDman wrote:
12 Sep 2022, 13:28
This is not a work-around solution and also not correct. As @mikeyww said, remove the hotkey label. What is left is

Code: Select all

Send, {PrintScreen}
Hi there. Unfortunately, you are wrong. The only way to actually perform Windows 10 Printscreen action - is to use a combination of Win and PrtScr keys.

the {PrintScreen} part will never execute the Windows 10 PrintScreen - Im talking about the process when you have visual response and the picture is saved to the Screenshots folder in Pictures directory. and Im not talkin about "Snip and Sketch" either.

So, to do this, you want to add the # modificator to indicate that you want to implement the exactly Windows 10 PrintScreen action.

On the opposite, the single {PrintScreen} that you propose makes only a copy of a screen to the clipboard.

In this case
- the file of a screenshot is not saved in "C:\...\Screenshots" directory.
- you dont receive a visual response when the picture is captured.
- you need to save the file from the clipboard separately
- and moreover, the next screenshot overwrites the previous screenshot. that is madness.

Try it yourself.

P.S.
I removed the hotkey label (this one :: ?) and replaced with "," , it works the same as with "::" version. I see no difference, both do the same job, and the result is identical
Just not to forget to add "return"

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Take a Screenshot by click on AHK script | Print Screen with AHK | {PrintScreen}

Post by flyingDman » 12 Sep 2022, 18:07

The :: should be removed, otherwise it will send :: to whatever the active window is. Send, {printscreen} takes a the screenshot and Send, #{printscreen} takes a screenshot and saves it to file. Nowhere in your original post did you mention that the screenshot needed to be saved... The issue is not whether it is {printscreen} or #{printscreen} (both of which I have used in scripts many times), it was the inclusion of ::. I am glad that that is resolved...
14.3 & 1.3.7

alf2314
Posts: 56
Joined: 05 Sep 2022, 13:29

Re: Take a Screenshot by click on AHK script | Print Screen with AHK | {PrintScreen}  Topic is solved

Post by alf2314 » 12 Sep 2022, 18:18

@flyingDman hello, the main issue in this misunderstood is that I wasnt even aware there is a {printScreen} option which does the job as it does.
I thought it is all about the Win Printscreen, which is just called "PrintScreen". But it is not. So I was sure it is clear that im describing the WinPrtScr process. From now I will indicate this difference in the future posts.

ok, now I see the difference of :: and ,
so, the correct version is:

Code: Select all

Send, #{PrintScreen}
?

sisatmp
Posts: 1
Joined: 03 Dec 2022, 06:01

Re: Take a Screenshot by click on AHK script | Print Screen with AHK | {PrintScreen}

Post by sisatmp » 03 Dec 2022, 06:15

I am trying to accomplish a simple screenshot script, where if I open a youtube video, it should click and take a screenshot and save in a file. I have put a second part in the script itself which should find the image of the 'already liked' blue thumbs-up button with website screenshots generator if yes, then take a screenshot and save the file.. The first part seems to be working, but not the second one if the video is already liked.

Please note that in the second condition, I am directly calling another AHK file which just takes the screenshot, as duplicate labels (CaptureScreen) are not allowed in this case.

Could you please help here:

Code: Select all

#Include, CaptureScreen.ahk ; assumes it's in the same folder 
as script

RAlt & k::
Run, https://seotoolsystem.com/website-screenshot-generatorwatch?v=lzs5u0jIYnQ
sleep, 5000
ErrorLevel:=1
While ErrorLevel
ImageSearch, foundX, foundY, 0, 0, A_ScreenWidth, 
A_ScreenHeight, *50 D:\huss\yt_like.png
if (!errorlevel){
sleep 500
Click, %foundX%, %foundY%
}
sleep 500
Mousemove 1268, 795
sleep 500
ScreenShot:
CaptureScreen(0, 0, "d:\YT\screenshot_" A_Now ".png")
sleep, 200

ErrorLevel:=1
While ErrorLevel
ImageSearch, foundX, foundY, 0, 0, A_ScreenWidth, 
A_ScreenHeight, *50 D:\huss\yt_liked.png
if (!errorlevel){
sleep 500
Run, D:\Huss\just_screenshot.ahk
sleep, 200
}
sleep 500
Mousemove 1268, 795
sleep 500
return

[Mod edit: Added [code][/code] tags and removed color and url tags.]

User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Take a Screenshot by click on AHK script | Print Screen with AHK | {PrintScreen}

Post by mikeyww » 03 Dec 2022, 08:44

https://www.autohotkey.com/docs/Scripts.htm#continuation-line:
Method #1: A line that starts with "and", "or", ||, &&, a comma, or a period is automatically merged with the line directly above it (in v1.0.46+, the same is true for all other expression operators except ++ and --).
Lines that do not meet these criteria are not continuation lines.

Post Reply

Return to “Ask for Help (v1)”