Create a shortcut for screen capture with region (snipping tool)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jelleeey
Posts: 33
Joined: 18 May 2021, 08:21

Create a shortcut for screen capture with region (snipping tool)

Post by Jelleeey » 18 May 2021, 10:20

Hello everyone,

Some context:
I am new to windows as I am a long time OSX user. I have used AHK to help make the transition to windows smoother as I am quite used to certain hotkeys on the mac. I am new to the forum and already got helped with another issue by the user SKAN (thank you so much!). In this thread I would like to ask about another shortcut.

My goal:
- I want to assign two shortcuts for creating a screenshot with a region box, preferably using the built in function called 'snipping tool'.
- shortcut 1: create a screenshot with region that saves the image to the desktop
- shortcut 2: create a screenshot with region that saves the image to the clipboard
- I know there is the windows + shift + S shortcut, but this cannot be used because I have disabled all the windows shortcuts in Gpedit.msc. This was done because these were conflicting with certain shortcuts for programs I am using.

Question:
- Is there a way to create a shortcut that doesnt link to win+shift+S but to the source script that is being triggered by this command.

Your help would really help me out tremendously as this function is quite essential for my everyday usage.

Greets Jelle
User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Create a shortcut for screen capture with region (snipping tool)

Post by mikeyww » 18 May 2021, 10:32

One example:

https://www.autohotkey.com/boards/viewtopic.php?p=360111#p360111

If you search the forum for "screenshot", I think you will find other examples.
Jelleeey
Posts: 33
Joined: 18 May 2021, 08:21

Re: Create a shortcut for screen capture with region (snipping tool)

Post by Jelleeey » 18 May 2021, 10:53

mikeyww wrote:
18 May 2021, 10:32
One example:

https://www.autohotkey.com/boards/viewtopic.php?p=360111#p360111

If you search the forum for "screenshot", I think you will find other examples.
Thank you ever so much for the reply. I forgot to mention that I am an absolute newbie when it comes to programming. I don't really know where to start if I look at the post you linked to. How should my shortcut code look like that could be directly implemented in my AHK file?
Jelleeey
Posts: 33
Joined: 18 May 2021, 08:21

Re: Create a shortcut for screen capture with region (snipping tool)

Post by Jelleeey » 18 May 2021, 11:21

Ok, I managed to get one of the hotkeys to work with the following code:

Run %A_WinDir%\System32\SnippingTool.exe /clip

this one will save a region to my clipboard, just like i want.

Now I need the same idea but instead of '/clip' it should be something else that will save the image to the desktop. Any ideas?
User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Create a shortcut for screen capture with region (snipping tool)

Post by mikeyww » 18 May 2021, 12:54

:arrow: GDI+

Code: Select all

#include q:\vis2\lib\Gdip_All.ahk ; Replace with your GDI path

F3::
pToken := Gdip_Startup(), snap := Gdip_CreateBitmapFromClipboard()
Gdip_SaveBitmapToFile(snap, out := A_Desktop "\test.png")
Gdip_DisposeImage(snap), Gdip_Shutdown(pToken)
Run, %out%
Return
Jelleeey
Posts: 33
Joined: 18 May 2021, 08:21

Re: Create a shortcut for screen capture with region (snipping tool)

Post by Jelleeey » 18 May 2021, 13:33

mikeyww wrote:
18 May 2021, 12:54
:arrow: GDI+

Code: Select all

#include q:\vis2\lib\Gdip_All.ahk ; Replace with your GDI path

F3::
pToken := Gdip_Startup(), snap := Gdip_CreateBitmapFromClipboard()
Gdip_SaveBitmapToFile(snap, out := A_Desktop "\test.png")
Gdip_DisposeImage(snap), Gdip_Shutdown(pToken)
Run, %out%
Return

Hi, I tried your code and I get this error message. I downloaded the Gdip_All.ahk file and inserted the proper GDI path like this

#include C:\Program Files\AutoHotkey\Gdip_All.ahk
LWin & 4::
pToken := Gdip_Startup(), snap := Gdip_CreateBitmapFromClipboard()
Gdip_SaveBitmapToFile(snap, out := "C:\Users\Jelle\Desktop\test.png")
Gdip_DisposeImage(snap), Gdip_Shutdown(pToken)
Run, %out%
Return

I made a picture of the error message as it is not possible to take a screenshot :P Any ideas?
Attachments
IMG_20210518_202024.jpg
IMG_20210518_202024.jpg (516.09 KiB) Viewed 1042 times
User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Create a shortcut for screen capture with region (snipping tool)

Post by mikeyww » 18 May 2021, 14:16

It works only if you have an image on your clipboard first. You can add a line that checks for existence of the file. Your previously mentioned approach could be used to get an image onto the clipboard, if that approach succeeded for you in doing that.
Jelleeey
Posts: 33
Joined: 18 May 2021, 08:21

Re: Create a shortcut for screen capture with region (snipping tool)

Post by Jelleeey » 20 May 2021, 04:58

mikeyww wrote:
18 May 2021, 14:16
It works only if you have an image on your clipboard first. You can add a line that checks for existence of the file. Your previously mentioned approach could be used to get an image onto the clipboard, if that approach succeeded for you in doing that.
Thanks Mikey,

I am more looking for a way to just automate this whole process with just one hotkey, as for my work I need to collect many, many screenshots. On the mac this process is very streamlined. You press cmd+shift+4 and it activates the rectangular box selection and after release it just creates a file on the desktop. It automatically names the file with the date and time the screenshot was made. I think I will just use a third party plugin as it seems that the native windows screenshot function does not have this kind of functionality. But thanks for the effort of helping me!
User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Create a shortcut for screen capture with region (snipping tool)

Post by mikeyww » 20 May 2021, 06:43

Here is a way to make a selection.

https://www.autohotkey.com/boards/viewtopic.php?p=360111#p360111

The selection box is invisible; could be changed with some work, but of course you can do this with a ready-made screenshot program, too.
Post Reply

Return to “Ask for Help (v1)”