how can i with pressing 1 load a image in to Clipboard and Paste it?

Get help with using AutoHotkey and its commands and hotkeys
Clemens375
Posts: 133
Joined: 11 May 2020, 11:54

how can i with pressing 1 load a image in to Clipboard and Paste it?

13 Oct 2020, 03:33

Hello,

how can i with pressing 1 load a image in to Clipboard and Paste it?

Image:
D:\0 BALDI VS GRANNY\129 Amoung Us 1\Render\Video\4_A6.png

Code: Select all

1::

sleep,500
Send ^v 
return


Thank you!
User avatar
mikeyww
Posts: 2336
Joined: 09 Sep 2014, 18:38

Re: how can i with pressing 1 load a image in to Clipboard and Paste it?

13 Oct 2020, 06:30

Code: Select all

1::
imageFile = D:\0 BALDI VS GRANNY\129 Amoung Us 1\Render\Video\4_A6.png
Clipboard =
FileToClipboard(imageFile)
ClipWait, 2
Sleep, 500
Send ^v
Return

FileToClipboard(PathToCopy, Method := "copy") {
 ; https://autohotkey.com/board/topic/23162-how-to-copy-a-file-to-the-clipboard/page-4
 FileCount := PathLength := 0
 Loop, Parse, PathToCopy, `n, `r ; Count files and total string length
  FileCount++, PathLength+=StrLen(A_LoopField)
 pid := DllCall("GetCurrentProcessId", "uint"), hwnd := WinExist("ahk_pid " . pid)
 ; 0x42 = GMEM_MOVEABLE(0x2) | GMEM_ZEROINIT(0x40)
 hPath := DllCall("GlobalAlloc", "uint", 0x42, "uint", 20 + (PathLength + FileCount + 1) * 2, "UPtr")
 pPath := DllCall("GlobalLock", "UPtr", hPath)
 NumPut(20, pPath+0), pPath += 16 ; DROPFILES.pFiles = offset of file list
 NumPut(1, pPath+0), pPath += 4 ; fWide = 0 -->ANSI, fWide = 1 -->Unicode
 Offset := 0
 Loop, Parse, PathToCopy, `n, `r ; Rows are delimited by linefeeds (`r`n)
  offset += StrPut(A_LoopField, pPath+offset, StrLen(A_LoopField)+1, "UTF-16") * 2
 DllCall("GlobalUnlock", "UPtr", hPath), DllCall("OpenClipboard", "UPtr", hwnd), DllCall("EmptyClipboard")
 DllCall("SetClipboardData", "uint", 0xF, "UPtr", hPath) ; 0xF = CF_HDROP
 ; Write Preferred DropEffect structure to clipboard to switch between copy/cut operations
 ; 0x42 = GMEM_MOVEABLE(0x2) | GMEM_ZEROINIT(0x40)
 mem := DllCall("GlobalAlloc", "uint", 0x42, "uint", 4, "UPtr"), str := DllCall("GlobalLock", "UPtr", mem)
 If !(Method ~= "copy|cut") {
  DllCall("CloseClipboard")
  Return
 } Else DllCall("RtlFillMemory", "UPtr", str, "uint", 1, "UChar", (Method = "copy" ? "0x05" : "0x02"))
 DllCall("GlobalUnlock", "UPtr", mem)
 cfFormat := DllCall("RegisterClipboardFormat", "Str", "Preferred DropEffect")
 DllCall("SetClipboardData", "uint", cfFormat, "UPtr", mem)
 DllCall("CloseClipboard")
}
MrDoge
Posts: 59
Joined: 27 Apr 2020, 21:29

Re: how can i with pressing 1 load a image in to Clipboard and Paste it?

13 Oct 2020, 10:07

if you meant this :
How do I copy an image file as only an image to the clipboard? - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/122225-how-do-i-copy-an-image-file-as-only-an-image-to-the-clipboard/

GDI+ standard library 1.45 by tic - AutoHotkey Community
https://www.autohotkey.com/boards/viewtopic.php?t=6517
User avatar
mikeyww
Posts: 2336
Joined: 09 Sep 2014, 18:38

Re: how can i with pressing 1 load a image in to Clipboard and Paste it?

13 Oct 2020, 10:13

Looks nice, but for some reason, that method did not work when I tried it, which is why I provided the other code instead. I was probably doing something the wrong way.
MrDoge
Posts: 59
Joined: 27 Apr 2020, 21:29

Re: how can i with pressing 1 load a image in to Clipboard and Paste it?

13 Oct 2020, 11:38

I renamed Gdip_All.ahk to Gdip.ahk
and I have Gdip.ahk in lib
User avatar
mikeyww
Posts: 2336
Joined: 09 Sep 2014, 18:38

Re: how can i with pressing 1 load a image in to Clipboard and Paste it?

13 Oct 2020, 11:53

Thanks. This may help. I think I was not accessing Gdip the right way.

Edit: worked!
User avatar
SKAN
Posts: 853
Joined: 29 Sep 2013, 16:58

SetClipboardBitmap

16 Oct 2020, 04:52

Setting a bitmap to clipboard is simple and shouldn't need any library.

Code: Select all

SetClipboardBitmap( Filename ) {            ; By SKAN on D3AG @ tiny.cc/setclipboardbitmap
Local  HBM := 0,  RES := 0,  OCB := 0,  CF_BITMAP := 2
  If ( HBM := LoadPicture(Filename) )
  If ( HBM := DllCall("CopyImage", "Ptr",HBM, "Int",0, "Int",0, "Int",0, "Int",8, "Ptr") )
  If ( OCB := DllCall("OpenClipboard", "Ptr",A_ScriptHwnd) )
  If DllCall("EmptyClipboard")
     RES := DllCall("SetClipboardData", "Int",CF_BITMAP, "Ptr",HBM)
  OCB := OCB ? DllCall("CloseClipboard")*0 : 0
  HBM := HBM ? DllCall("DeleteObject", "Ptr",HBM)*0 : 0
Return !!RES
}
User avatar
mikeyww
Posts: 2336
Joined: 09 Sep 2014, 18:38

Re: how can i with pressing 1 load a image in to Clipboard and Paste it?

16 Oct 2020, 07:09

It doesn't look simple to me-- but works! Thanks.
User avatar
SKAN
Posts: 853
Joined: 29 Sep 2013, 16:58

Re: how can i with pressing 1 load a image in to Clipboard and Paste it?

16 Oct 2020, 07:53

mikeyww wrote:
16 Oct 2020, 07:09
It doesn't look simple to me
When you see DllCall()'s without any structures involved, then it is fairly simple. :)
Also CF_BITMAP is deprecated and the OS will automatically (Vista+) create both CF_DIB and CF_DIBV5 when a CF_BITMAP is supplied.
In other words: This is a simple function that makes the OS do the work.

Return to “Ask For Help”

Who is online

Users browsing this forum: AlexIII, Bing [Bot], CluelessHotKeyUser, mikeyww, murataygun and 41 guests