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!
Code: Select all
1::
sleep,500
Send ^v
return
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")
}
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
}
When you see DllCall()'s without any structures involved, then it is fairly simple.
Code: Select all
#+.::
SetClipboardBitmap( D:\TT-AF Dropbox\hal myers\_SIGNATURE FILES\ Hals signature1-blue.bmp)
{ Local HBM := 0, RES := 0, OCB := 0, CF_BITMAP := 2
If ( HBM := LoadPicture( D:\TT-AF Dropbox\hal myers\_SIGNATURE FILES\ Hals signature1-blue.bmp) )
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
}
Code: Select all
#+.::SetClipboardBitmap("D:\TT-AF Dropbox\hal myers\_SIGNATURE FILES\ Hals signature1-blue.bmp")
SetClipboardBitmap( Filename ) { ; By SKAN on D3AG @ tiny.cc/setclipboardbitmap
Local HBM := 0, RES := 0, OCB := 0, CF_BITMAP := 2
If !FileExist(Filename) {
MsgBox, 48, Error, File not found. Aborting.`n`n%Filename%
Return
}
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
}
Code: Select all
<textarea id="textarea"></textarea>
<script>
const textarea = document.getElementById("textarea")
textarea.addEventListener("paste", event=>{
var items = event.clipboardData.items;
console.log(items)
console.log(JSON.stringify(items)); // might give you mime types
for (var index in items) {
var item = items[index];
console.log("kind", item.kind)
if (item.kind === 'file') {
var blob = item.getAsFile();
var reader = new FileReader();
reader.onload = function (event) {
console.log(event.target.result); // data url!
};
reader.readAsDataURL(blob);
} else if (item.kind === 'string') {
item.getAsString(data=>{
console.log(data)
})
}
}
})
</script>
Code: Select all
#Requires AutoHotkey v1.1.33
#Include d:\Q\vis2\lib\Gdip_All.ahk ; https://github.com/marius-sucan/AHK-GDIp-Library-Compilation
picsDir := StrReplace(A_Desktop, "Desktop", "Pictures")
image := picsDir "\abc 3.webp"
F3::imgToClipboard(image)
imgToClipboard(imagePath){
pToken := Gdip_Startup()
hBitmap := HBitmapFromWebP(imagePath, width, height)
Gdip_SetBitmapToClipboard(pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap))
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
SoundBeep 1500
}
Code: Select all
#SingleInstance force
ListLines 0
KeyHistory 0
SendMode "Input" ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir A_ScriptDir ; Ensures a consistent starting directory.
filesToClipboard(filePathsArr) {
totalSize:=11 + filePathsArr.Length ;filePathsArr.Length for 0 terminated strings, 10 for 20, 1 for 0x0000 ending of string array
for filePath in filePathsArr {
totalSize+=StrLen(filePath) ;AHK String is internally UTF-16, I assume
}
totalSize*=2
buf:=Buffer(totalSize)
NumPut("UInt64",0x0000000000000014,buf,0x0)
NumPut("UInt64",0x0000000000000000,buf,0x8)
NumPut("UChar",0x00000001,buf,0x10)
pointer:=buf.Ptr + 20
for filePath in filePathsArr {
pointer+=StrPut(filePath,pointer,"UTF-16")
}
NumPut("UShort",0x0000,pointer)
;buf filled
DllCall("OpenClipboard", "Ptr",0)
DllCall("EmptyClipboard")
DllCall("SetClipboardData","Uint",15,"Ptr",buf) ;15=CF_HDROP
DllCall("CloseClipboard")
}
filesToClipboard(["C:\Users\User\Downloads\img1.webp","C:\Users\User\Downloads\img2.webp"])
Exitapp
f3::Exitapp