how to store screenshot in a variable, then paste it later?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
alawsareps
Posts: 26
Joined: 20 Jul 2016, 09:28

how to store screenshot in a variable, then paste it later?

Post by alawsareps » 11 May 2024, 09:14

Something like this:

Code: Select all

f1:: {
    send("{printscreen}")
    screenshot := A_Screenshot
}

f3:: {
    ;----- PASTE SCREENSHOT
    send(screenshot)
}


Last edited by alawsareps on 11 May 2024, 12:05, edited 1 time in total.
User avatar
WarlordAkamu67
Posts: 226
Joined: 21 Mar 2023, 06:52

Re: how to store screenshot in a variable, then paste it later?

Post by WarlordAkamu67 » 11 May 2024, 09:50

Depending on what you really want, you may be able to send printscreen. Another option is to use a library such as ImagePut by iseahound. Here is GitHub documentation that shows how to use it.
User avatar
xMaxrayx
Posts: 203
Joined: 06 Dec 2022, 02:56
Contact:

Re: how to store screenshot in a variable, then paste it later?

Post by xMaxrayx » 11 May 2024, 10:02

idk if autohotkey support binary data as variable like python, as I know it's just straight string type variables

if you want use python you can do this (if the screenshot saved in clipboard)

Code: Select all

clipboard_image = ImageGrab.grabclipboard()
you need to import PIL, then you can have some libraries if you want edit it.

then if you want send the image isn't that easy with just line you need to write which format-type for win clipboard
https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats

you can also, register a new type like 'PNG' but it wont be accepted to all software
I think you can use more than one (clipboard format-type)

notice win clipboard history future =/= normal windows clipboard, the first one seems like external software but maybe i'm wrong.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/
User avatar
Noitalommi_2
Posts: 278
Joined: 16 Aug 2023, 10:58

Re: how to store screenshot in a variable, then paste it later?

Post by Noitalommi_2 » 11 May 2024, 10:16

Hi.

You could use ClipboardAll for that task.

Code: Select all

#Requires AutoHotkey 2.0
#SingleInstance


F1:: ; takes a screenshot
F2:: { ; restores the screenshot

	static ClipSaved := ""
	if ThisHotkey = "F1" {

		A_Clipboard := ""
		Send "{LWin down}{F24}{LWin up}"
		ClipWait , 1
		ClipSaved := ClipboardAll()
		SoundBeep
	}
	else A_Clipboard := ClipSaved, SoundBeep(600)
}
Last edited by Noitalommi_2 on 11 May 2024, 12:36, edited 1 time in total.
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: how to store screenshot in a variable, then paste it later?

Post by mikeyww » 11 May 2024, 10:42

More: viewtopic.php?f=83&t=115622#p515378

Or:

Code: Select all

#Requires AutoHotkey v2.0
; https://github.com/buliasz/AHKv2-Gdip
#Include d:\Q\vis2\lib\Gdip_AllV2.ahk
pToken := Gdip_Startup()
pos    := '0|0|' A_ScreenWidth '|' A_ScreenHeight
OnExit done

F2:: {
 Global pBitmap := Gdip_BitmapFromScreen(pos)
 SoundBeep 1500
}

F3:: {
 A_Clipboard := ''
 Try Gdip_SetBitmapToClipboard(pBitmap)
 Catch
  Return MsgBox('Nothing has been copied.', 'Error', 'Icon!')
 If ClipWait(1, ANY := True) {
  Send '^v'
  SoundBeep 1000
 } Else MsgBox 'An error occurred while waiting for the clipboard.', 'Error', 'Icon!'
}

done(exitReason, exitCode) {
 Try Gdip_DisposeImage(pBitmap), Gdip_Shutdown(pToken)
 SoundBeep 2500
}
Post Reply

Return to “Ask for Help (v2)”