[how to] simulated drag, then drop

Get help with using AutoHotkey and its commands and hotkeys
beeski
Posts: 17
Joined: 06 Feb 2014, 08:38

[how to] simulated drag, then drop

19 Aug 2014, 06:46

hello

i tried bringing up this issue over at the autohotkey forum, but maybe i could get some suggestions here as well.

i cannot seem to be able to come up with a solution to perform the following:
--simulate a drag and drop operation (probably using COM), however
--instead of doing it all at once, let the user manually focus the window & coordinates where the drop should be performed, then, following a hotkey, perform the drop to whichever window appears active at the time, at whichever mouse coordinates the cursor is at. basically a drag&drop using keyboard shortcuts as opposed to a mouse click & drag.

after following some suggested past solutions, i was able to simulate a file-drop operation into some applications. for some (they happen to be utilizing a lot of child windows), my implementation is not working.*

here is what i am using at the moment:

Code: Select all

#a::
MouseGetPos, MouseCoordX, MouseCoordY, WindowUnderMouse, , ,
WindowToDropTo := "ahk_id "WindowUnderMouse
PostMessage, 0x233, HDrop(SubPat1, MouseCoordX, MouseCoordY), 0, , %WindowToDropTo%
;NOTE:
;SubPat1 contains the file path & filename

Code: Select all

HDrop(fnames,x,y) {
   fns:=RegExReplace(fnames,"\n$")
   fns:=RegExReplace(fns,"^\n")
   hDrop:=DllCall("GlobalAlloc","UInt",0x42,"UInt",20+StrLen(fns)+2)
   p:=DllCall("GlobalLock","UInt",hDrop)
   NumPut(20, p+0)  ;offset
   NumPut(x,  p+4)  ;pt.x
   NumPut(y,  p+8)  ;pt.y
   NumPut(0,  p+12) ;fNC
   NumPut(0,  p+16) ;fWide
   p2:=p+20
   Loop,Parse,fns,`n,`r
   {
      DllCall("RtlMoveMemory","UInt",p2,"Str",A_LoopField,"UInt",StrLen(A_LoopField))
      p2+=StrLen(A_LoopField)+1
   }
   DllCall("GlobalUnlock","UInt",hDrop)
   Return hDrop
}
has anyone taken a shot at a similar task? would anyone be able to suggest why this does not work for some applications (that will otherwise process a file dropped in the standard manual fashion)?

thank you!


*i furthermore realised that some applications perform more advanced tasks when the user is about to drop a file: for instance, hovering on top of a control for x amount of seconds within an application whilst dragging a file, the application may further adjust how it will deal with the file once the LMB is released and the drop is performed. i wonder if there is a way to simulate this; basically this introduces one more layer to the operation, not just the dropping itself, but the state before the drop to which certain applications may react in a specific way...
beeski
Posts: 17
Joined: 06 Feb 2014, 08:38

Re: [how to] simulated drag, then drop

19 Aug 2014, 13:48

it appears this has to be implemented using DoDragDrop(), IDropSource and IDataObject. now how to do this, i have no idea unfortunately...
beeski
Posts: 17
Joined: 06 Feb 2014, 08:38

Re: [how to] simulated drag, then drop

06 Mar 2016, 10:37

thank you for the heads up! :)

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Bing [Bot], Odlanir and 169 guests