How to paste image?

Get help with using AutoHotkey and its commands and hotkeys
m3user
Posts: 107
Joined: 17 Jan 2014, 18:11

How to paste image?

25 Apr 2014, 01:44

Hi, I have an image on disk which I would frequently like to paste to my documents using a hotkey. How is this possible? Thanks.
Leefme
Posts: 90
Joined: 30 Sep 2013, 22:13

Re: How to paste image?

25 Apr 2014, 06:39

1. copy the image to the clipboard
2. paste the image from clipboard to application using ^v (from keyboard)

there is a script that does step 1, here
http://www.autohotkey.com/board/topic/5 ... clipboard/
m3user
Posts: 107
Joined: 17 Jan 2014, 18:11

Re: How to paste image?

25 Apr 2014, 08:24

Thank you! I see it is very complicated, it requires gdi library. No simpler solutions?
vasili111
Posts: 747
Joined: 21 Jan 2014, 02:04
Location: Georgia

Re: How to paste image?

25 Apr 2014, 08:57

If I understand your question correctly, you have image file somewhere on your hdd and you want that file to be coped to your documents folder. In that case you dont need to use paste, you can use FileCopy command ( http://ahkscript.org/docs/commands/FileCopy.htm ) to copy file from one location to another.
DRAKON-AutoHotkey: Visual programming for AutoHotkey.
Leefme
Posts: 90
Joined: 30 Sep 2013, 22:13

Re: How to paste image?

25 Apr 2014, 09:06

>>No simpler solutions?

open the image in a paint program and copy it (so it goes to the clipboard)
Run the following script and press F1, to store the image to a file (in AHk's clipboard format)

Later, run the script and press F2, to copy the image from the stored file back to the clipboard.
Then press ^v to paste the contents of the clipboard whereever you want.


; store an image from the clipboard to a file
f1::
FileAppend, %ClipboardAll%, my_clip_image.img ; The file extension does not matter.
return

; read an image from a file into the clipboard
f2::
FileRead, Clipboard, *c my_clip_image.img ; Note the use of *c, which must precede the filename.
return
m3user
Posts: 107
Joined: 17 Jan 2014, 18:11

Re: How to paste image?

25 Apr 2014, 14:51

Thank you Leefme, I learned something new.

Vasili, My wish was to create a signature (which would include an image) that could be pasted to Word (or other application) using a hotkey.

I understand the main problem is how to directly copy any image from disk to clipboard and that there are no simple functions for doing this.
FanaticGuru
Posts: 1193
Joined: 30 Sep 2013, 22:25

Re: How to paste image?

25 Apr 2014, 16:08

m3user wrote:Thank you Leefme, I learned something new.
This is a good technique to know for easy Microsoft Office automation.

There are lot of fancy ways to interact with Office but it is sometimes just simpler to get what you want on the clipboard once, then save the clipboard to a file. And from then on, have AHK retrieve the correct file and paste if for you. It could be an email template, signature, Excel table, etc.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

[Function] Timer - Create and Manage Timers
tmplinshi
Posts: 1267
Joined: 01 Oct 2013, 14:57

Re: How to paste image?

26 Apr 2014, 00:28

Some solutions:
  1. You can record macros in Microsoft Word, it also allows you to assign a hotkey.
  2. The GDI method mentioned by Leefme. The usage is very simple.

    Code: Select all

    #Include <Gdip_All> ; http://www.autohotkey.net/~Rseding91/Gdip%20All/Gdip_All.ahk
    CopyImage("test.jpg")
    
    CopyImage(ImageFile) {
    	pToken := Gdip_Startup()
    	Gdip_SetBitmapToClipboard(pBitmap := Gdip_CreateBitmapFromFile(ImageFile))
    	Gdip_DisposeImage(pBitmap)
    	Gdip_Shutdown(pToken)
    }
  3. Set "HTML clipboard"

    Code: Select all

    ; WinClip by Deo:
    ; -> http://www.autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/
    #Include <WinClipAPI>
    #Include <WinClip>
    
    CopyImage("test.jpg")
    
    CopyImage(ImageFile) {
    	WinClip.Clear()
    
    	; Make sure ImageFile is full path
    	Loop, %ImageFile%
    		ImageFile := A_LoopFileLongPath
    
    	WinClip.SetHTML( "<IMG src=""" ImageFile """>" )
    
    	; Below two lines might not needed.
    	WinClip.SetFiles( ImageFile )
    	WinClip.SetBitmap( ImageFile )
    }
  4. Use a command line tool, such as irfanview.

    Code: Select all

    RunWait, i_view32.exe "c:\test.jpg" /clipcopy /cmdexit
m3user
Posts: 107
Joined: 17 Jan 2014, 18:11

Re: How to paste image?

04 May 2014, 14:18

Thank you tmplinshi, I'll test it and decide between Gdip and WinClip.

Return to “Ask For Help”

Who is online

Users browsing this forum: andremarasca, Google [Bot], Scr1pter and 27 guests