Simulate drag and drop file onto app?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
redrum
Posts: 83
Joined: 25 Jan 2015, 22:57

Simulate drag and drop file onto app?

20 Oct 2017, 23:12

Is there a relatively easy to understand script that will take a filepath/filename and an app/window title and drop the file onto the specified window? This would be for Windows 7.

It's not a big deal to perform the manual drag/drop, but it's something I have to do 1x/week so if it's not difficult to automate, that would be nice to do.

I found this: https://autohotkey.com/board/topic/4146 ... ntry638376
but it's a bit over my head.
User avatar
noname
Posts: 515
Joined: 19 Nov 2013, 09:15

Re: Simulate drag and drop file onto app?

22 Oct 2017, 07:28

Here is an example that drops a list of files on the PSPad editor where they open in tabs ( win10 pro and ahk unicode 1.1.26.01 )

Code: Select all

SetTitleMatchMode, 2

list_files:={} ;define array name

data=
(
c:\Users\momoko\AppData\Roaming\ahk\run avi\avitoday.ahk
c:\Users\momoko\AppData\Roaming\ahk\run avi\clipverify.ahk
c:\Users\momoko\AppData\Roaming\ahk\run avi\copy selected avi.ahk
c:\Users\momoko\AppData\Roaming\ahk\run avi\ddd.ahk
c:\Users\momoko\AppData\Roaming\ahk\run avi\del files.ahk
)


loop,parse,data,`n,`r
list_files[A_Index]:=A_LoopField


DropFiles("PSPad", list_files)

DropFiles(window, files)
{
  for k,v in files
    memRequired+=StrLen(v)+1
  hGlobal := DllCall("GlobalAlloc", "uint", 0x42, "ptr", memRequired+21)
  dropfiles := DllCall("GlobalLock", "ptr", hGlobal)
  NumPut(offset := 20, dropfiles+0, 0, "uint")
  for k,v in files
    StrPut(v, dropfiles+offset, "utf-8"), offset+=StrLen(v)+1
  DllCall("GlobalUnlock", "ptr", hGlobal)
  PostMessage, 0x233, hGlobal, 0,, %window%
  if ErrorLevel
    DllCall("GlobalFree", "ptr", hGlobal)
}





Enlprck
Posts: 5
Joined: 15 Mar 2019, 05:35

Re: Simulate drag and drop file onto app?

12 Sep 2019, 04:55

noname wrote:
22 Oct 2017, 07:28
Here is an example that drops a list of files on the PSPad editor where they open in tabs ( win10 pro and ahk unicode 1.1.26.01 )

Code: Select all

SetTitleMatchMode, 2

list_files:={} ;define array name

data=
(
c:\Users\momoko\AppData\Roaming\ahk\run avi\avitoday.ahk
c:\Users\momoko\AppData\Roaming\ahk\run avi\clipverify.ahk
c:\Users\momoko\AppData\Roaming\ahk\run avi\copy selected avi.ahk
c:\Users\momoko\AppData\Roaming\ahk\run avi\ddd.ahk
c:\Users\momoko\AppData\Roaming\ahk\run avi\del files.ahk
)


loop,parse,data,`n,`r
list_files[A_Index]:=A_LoopField


DropFiles("PSPad", list_files)

DropFiles(window, files)
{
  for k,v in files
    memRequired+=StrLen(v)+1
  hGlobal := DllCall("GlobalAlloc", "uint", 0x42, "ptr", memRequired+21)
  dropfiles := DllCall("GlobalLock", "ptr", hGlobal)
  NumPut(offset := 20, dropfiles+0, 0, "uint")
  for k,v in files
    StrPut(v, dropfiles+offset, "utf-8"), offset+=StrLen(v)+1
  DllCall("GlobalUnlock", "ptr", hGlobal)
  PostMessage, 0x233, hGlobal, 0,, %window%
  if ErrorLevel
    DllCall("GlobalFree", "ptr", hGlobal)
}





Firstly I appreciate to you for sharing it.

I have simple A.txt file on my desktop. Lets say I want to that A file drop onto "ahk_class Notepad" and when I try it It works perfect!

However, I have a ahk_class X, window and whenever i try to drop onto that "X" window it's not work for me. Any Idea about it?

I think the problem is with X windows because when I manually drag & drop onto that X window ( Just title area ) it's not work ofc when I put it manually onto that window ARENA (not title arena) it's work.

When I drag & drop manually onto Notepad (title ARENA) it's work.

So I think It's about Notepad title arena accepting to drop , but X window is not accept.

So is there any change to fix it for my X window? It maybe about 0x42 or 0x233 stuffs but I have really no idea because I cannot understand those codes. Thank you for helping us.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: inseption86, jaka1, metallizer, Rohwedder and 336 guests