one key press, paste picture from the drive to WhatsApp

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
vikasgandhi
Posts: 32
Joined: 03 Jul 2021, 20:28

one key press, paste picture from the drive to WhatsApp

Post by vikasgandhi » 01 Apr 2023, 03:39

Let's say, I have a JPG in "D:\photo\FREEWIN.JPG"

When I reply an WHATSAPP, I want to paste this photo in WHATSAPP MESSAGE, with a hotkey "F1"

You help is much appreciated.

note: No Copy, Only paste, by pressing only one key i.e. F1

Thanks
Vikas

User avatar
mikeyww
Posts: 26857
Joined: 09 Sep 2014, 18:38

Re: one key press, paste picture from the drive to WhatsApp

Post by mikeyww » 01 Apr 2023, 05:48

Code: Select all

; This script uses a hotkey to paste an image
#Requires AutoHotkey v1.1.33
image := "d:\photo\FREEWIN.jpg"
If !FileExist(image)
 MsgBox 48, Error, File not found.`n`n%image%

F1::  ; F1 = Paste image
Clipboard := ""
setClipboardBitmap(image)
ClipWait 0, WaitForAnyData := True
If ErrorLevel
 MsgBox 48, Error, An error occurred while waiting for the clipboard.
Else Send ^v
Return

setClipboardBitmap(Filename) { ; By SKAN on D3AG @ tiny.cc/setclipboardbitmap
 Local HBM := RES := 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
}

vikasgandhi
Posts: 32
Joined: 03 Jul 2021, 20:28

Re: one key press, paste picture from the drive to WhatsApp

Post by vikasgandhi » 22 Mar 2024, 08:28

sir, please help us, I am trying to merge 3 script into one, but couldn't do

I have try to merge the below 3 mentioned script into one, namely FA


FA SCRIPT

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.






#NoTrayIcon

; This script uses a hotkey to paste an image
#Requires AutoHotkey v1.1.33
image := "D:\TEXT_DATA\ivr1.jpg"

If !FileExist(image)
 MsgBox 48, Error, File not found.`n`n%image%

+F1::  ; SHIFT+F1 = Paste image



Clipboard := ""
setClipboardBitmap(image)
ClipWait 0, WaitForAnyData := True
If ErrorLevel
 MsgBox 48, Error, An error occurred while waiting for the clipboard.
Else Send ^v
Return

setClipboardBitmap(filename) { ; By SKAN on D3AG @ tiny.cc/setclipboardbitmap
 Local HBM := RES := 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
}


return





#NoTrayIcon

; This script uses a hotkey to paste an image
#Requires AutoHotkey v1.1.33
image := "D:\TEXT_DATA\ivr2.jpg"

If !FileExist(image)
 MsgBox 48, Error, File not found.`n`n%image%

+F2::  ; SHIFT+F2 = Paste image



Clipboard := ""
setClipboardBitmap(image)
ClipWait 0, WaitForAnyData := True
If ErrorLevel
 MsgBox 48, Error, An error occurred while waiting for the clipboard.
Else Send ^v
Return

setClipboardBitmap(filename) { ; By SKAN on D3AG @ tiny.cc/setclipboardbitmap
 Local HBM := RES := 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
}


return








#NoTrayIcon

; This script uses a hotkey to paste an image
#Requires AutoHotkey v1.1.33
image := "D:\TEXT_DATA\ivr3.jpg"

If !FileExist(image)
 MsgBox 48, Error, File not found.`n`n%image%

+F3::  ; SHIFT+F3 = Paste image



Clipboard := ""
setClipboardBitmap(image)
ClipWait 0, WaitForAnyData := True
If ErrorLevel
 MsgBox 48, Error, An error occurred while waiting for the clipboard.
Else Send ^v
Return

setClipboardBitmap(filename) { ; By SKAN on D3AG @ tiny.cc/setclipboardbitmap
 Local HBM := RES := 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
}


return




But it shows error, when we compile it :-
image.png
image.png (16.62 KiB) Viewed 32 times
Error: The script contains syntax errors.
Specifically:
Z:\Other computers\My
Laptop\SOLD[A]\ARCHIVE\KNOWLEDGE BASE\IVR-MICROSFOT
TELEPHONE ACTIVATION\IVR_24_O3_16_O1_19_02\FA.ahk (72) :
==> Duplicate function definition.
Specificallm setClipboardBitmap[filename]


Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.






#NoTrayIcon

; This script uses a hotkey to paste an image
#Requires AutoHotkey v1.1.33
image := "D:\TEXT_DATA\ivr1.jpg"

If !FileExist(image)
 MsgBox 48, Error, File not found.`n`n%image%

+F1::  ; SHIFT+F1 = Paste image



Clipboard := ""
setClipboardBitmap(image)
ClipWait 0, WaitForAnyData := True
If ErrorLevel
 MsgBox 48, Error, An error occurred while waiting for the clipboard.
Else Send ^v
Return

setClipboardBitmap(filename) { ; By SKAN on D3AG @ tiny.cc/setclipboardbitmap
 Local HBM := RES := 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
}


return





Code: Select all


#NoTrayIcon

; This script uses a hotkey to paste an image
#Requires AutoHotkey v1.1.33
image := "D:\TEXT_DATA\ivr2.jpg"

If !FileExist(image)
 MsgBox 48, Error, File not found.`n`n%image%

+F2::  ; SHIFT+F2 = Paste image



Clipboard := ""
setClipboardBitmap(image)
ClipWait 0, WaitForAnyData := True
If ErrorLevel
 MsgBox 48, Error, An error occurred while waiting for the clipboard.
Else Send ^v
Return

setClipboardBitmap(filename) { ; By SKAN on D3AG @ tiny.cc/setclipboardbitmap
 Local HBM := RES := 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
}


return




Code: Select all


#NoTrayIcon

; This script uses a hotkey to paste an image
#Requires AutoHotkey v1.1.33
image := "D:\TEXT_DATA\ivr3.jpg"

If !FileExist(image)
 MsgBox 48, Error, File not found.`n`n%image%

+F3::  ; SHIFT+F3 = Paste image



Clipboard := ""
setClipboardBitmap(image)
ClipWait 0, WaitForAnyData := True
If ErrorLevel
 MsgBox 48, Error, An error occurred while waiting for the clipboard.
Else Send ^v
Return

setClipboardBitmap(filename) { ; By SKAN on D3AG @ tiny.cc/setclipboardbitmap
 Local HBM := RES := 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
}


return




Thanks
Attachments
image.png
image.png (16.62 KiB) Viewed 32 times

User avatar
mikeyww
Posts: 26857
Joined: 09 Sep 2014, 18:38

Re: one key press, paste picture from the drive to WhatsApp

Post by mikeyww » 22 Mar 2024, 08:48

Do not repeat the function definition in your script. You need just one instance of your function definition.

To work with different images, you can define your image path in the hotkey subroutine instead of at the top of the script.

Code: Select all

; This script uses hotkeys to paste an image
#Requires AutoHotkey v1.1.33
image := ["p1", "p2", "p3"]

+F1::
+F2::
+F3::
Clipboard := ""
setClipboardBitmap("D:\photo\" image[SubStr(A_ThisHotkey, 0)] ".png")
ClipWait 0, WaitForAnyData := True
If ErrorLevel
 MsgBox 48, Error, An error occurred while waiting for the clipboard.
Else Send ^v
Return

setClipboardBitmap(Filename) { ; By SKAN on D3AG @ tiny.cc/setclipboardbitmap
 Local HBM := RES := 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
}

Post Reply

Return to “Ask for Help (v1)”