How to copy file to clipboard (from specific path) and paste?

Discussion, questions and support.
Post Reply
cadudesun
Posts: 103
Joined: Jun 6th, ’15, 03:28

Post by cadudesun » Apr 24th, ’19, 18:26

Hello,

I'd appreciate your help.

I have some template files stored in specific paths, for instance:
C:\TEMPLATES\File.pdf
C:\TEMPLATES\File.docx
C:\TEMPLATES\File.png

I'm trying to build a start menu "TEMPLATE" in FastKeys like that:
Template PDF
Template DOCX
Template PNG

When clicking the menu item (e.g. "Template DOCX"), the script should:
(1) copy that specific file from the path (C:\TEMPLATES\File.docx) to the clipboard
(2) paste the full file (File.docx)

Does anyone know how to do that?

Thank you very much!
Carlos
cadudesun
Posts: 103
Joined: Jun 6th, ’15, 03:28

Post by cadudesun » Apr 27th, ’19, 18:43

Regarding the main part of the scrip, which is "copy a file from a specified path", I tried - without success - to use the syntaxes available at the last page of this topic:
https://autohotkey.com/board/topic/2316 ... ard/page-4
Fastkeys is poping-up an error message.

Also, I'm wondering if I so complex syntax (from the topic above) is needed to just copy a file from a specified path.

Does anyone have further information on how to copy a file from a specified path?

Thank you!
SaraJubaro5
Posts: 3
Joined: May 20th, ’19, 15:04

Post by SaraJubaro5 » May 20th, ’19, 15:05

thanks
cadudesun
Posts: 103
Joined: Jun 6th, ’15, 03:28

Post by cadudesun » May 26th, ’19, 14:54

Hi,
I'm still without finding out a solution.
I recorded a screencast detailing what I'm trying to implement in Fastkeys: http://bit.ly/2VQpFfi
Any direction?
Thank you very much!
Carlos
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jun 3rd, ’19, 11:33

Hi Carlos, as you may have figured it out, this is not that easy. There are some functions available - could you try them with a new 4.19 version?
https://www.autohotkey.com/boards/viewt ... =6&t=64052
https://autohotkey.com/board/topic/2316 ... ard/page-4
cadudesun
Posts: 103
Joined: Jun 6th, ’15, 03:28

Post by cadudesun » Jun 3rd, ’19, 12:13

Marko wrote: Jun 3rd, ’19, 11:33 Hi Carlos, as you may have figured it out, this is not that easy. There are some functions available - could you try them with a new 4.19 version?
Hi Marko, this was a tough one!
Many thanks for addressing it!
Could you please inform the functions for testing?
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jun 3rd, ’19, 13:26

I made a shortcut with the command below and it works for me. :D

Code: Select all

FileToClipboard("H:\folder\file.png")
sleep 1000
send, ^v
return


FileToClipboard(PathToCopy,Method="copy")
   {
   FileCount:=0
   PathLength:=0

   ; Count files and total string length
   Loop,Parse,PathToCopy,`n,`r
      {
      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")
      DllCall("RtlFillMemory","UPtr",str,"uint",1,"UChar",0x05)
   else if (Method="cut")
      DllCall("RtlFillMemory","UPtr",str,"uint",1,"UChar",0x02)
   else
      {
      DllCall("CloseClipboard")
      return
      }

   DllCall("GlobalUnlock","UPtr",mem)

   cfFormat := DllCall("RegisterClipboardFormat","Str","Preferred DropEffect")
   DllCall("SetClipboardData","uint",cfFormat,"UPtr",mem)
   DllCall("CloseClipboard")
   return
   }
cadudesun
Posts: 103
Joined: Jun 6th, ’15, 03:28

Post by cadudesun » Jun 8th, ’19, 12:45

Hi Marko,
The script works marvelously! Thank you!
IMO this is a very handy functionality.
I would suggest you add it as a drop-down start menu item type (snapshot below).
For instance, when "template" is selected, a field to add the file path would appear.
From the user side, it is necessary just to enter the file path, and the AHK command would work in the background (no need to the user edit the command directly).
Another possibility could be to approach "templates" more systematically, including it as a FastKeys module (snapshot below).
Best,
Carlos

TEMPLATE as start menu item type
Image

TEMPLATE as Fastkeys module.
Image
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jun 8th, ’19, 13:38

What are the usage examples of such templates?
cadudesun
Posts: 103
Joined: Jun 6th, ’15, 03:28

Post by cadudesun » Jun 8th, ’19, 14:32

Marko wrote: Jun 8th, ’19, 13:38 What are the usage examples of such templates?
Think about having in a single place (FastKeys) all templates for every software you use.
In other words, think on Fastkeys as a hub for templates (Word, Excel, AHK script, etc.).
From the file explorer, just select through AHK start menu (snapshot below) the template you want and the file is pasted immediately, being ready to use.
Having the script now, I'm going to start building a TEMPLATE menu in FastKeys, and I update you when it is more evolved.

Image
Post Reply