Sending file (not contents) to clipboard for later pasting

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Snich
Posts: 1
Joined: 23 Oct 2021, 10:31

Sending file (not contents) to clipboard for later pasting

Post by Snich » 23 Oct 2021, 10:48

How to copy file (not contents) to clipboard for to be pasted later? I have a script that saves my screenshot to a specific folder when I hit PrtScr, but I want to change it. Instead of saving it to a directory, I want to be a file on the Clipboard so I can paste it easily anywhere, just like copying a file.

https://www.autohotkey.com/board/topic/23162-how-to-copy-a-file-to-the-clipboard/page-1
I found this thread, but it does make the "Paste" option active on the context menu, but nothing really is being pasted.


Here is my AHK script: screenshot -> save file

Code: Select all

#SingleInstance, Force
SetBatchLines, -1

#Include Gdip_All.ahk
#Include FileToClipboard.ahk

class SaveScreen
{

    ; the first version was, file is being save on "<username>\Pictures\Screenshot"
    static Directory := A_AppData . "\DarkWare\shrtct\temp_scrnsht\" ; temp folder before copying the file
    static FilePath := SaveScreen.Directory . A_Now . ".png"
    static Size := 1.0

    Save()
    {
        If !pToken := Gdip_Startup()
        {
          MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
          ExitApp
        }
        OnExit("ExitFunc")

        FileCreateDir % SaveScreen.Directory
        pBitmap := Gdip_BitmapFromScreen()
        Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)
        PBitmapResized := Gdip_CreateBitmap(Round(Width*SaveScreen.Size), Round(Height*SaveScreen.Size)), G := Gdip_GraphicsFromImage(pBitmapResized)
        Gdip_DrawImage(G, pBitmap, 0, 0, Round(Width*SaveScreen.Size), Round(Height*SaveScreen.Size), 0, 0, Width, Height)
        Gdip_SaveBitmapToFile(PBitmapResized, SaveScreen.FilePath)
        Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapResized)
        Gdip_DisposeImage(pBitmap)
        FileToClipboard(SaveScreen.FilePath)
        Return
    }
}


ExitFunc(ExitReason, ExitCode)
{
    Gdip_Shutdown(pToken)
    ExitApp
    Return
}

Return to “Ask for Help (v1)”