Page 1 of 1

[how to] simulated drag, then drop

Posted: 19 Aug 2014, 06:46
by beeski

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

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

Code: Select all

HDrop(fnames,x,y) {
   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
   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...

Re: [how to] simulated drag, then drop

Posted: 19 Aug 2014, 13:48
by beeski
it appears this has to be implemented using DoDragDrop(), IDropSource and IDataObject. now how to do this, i have no idea unfortunately...

Re: [how to] simulated drag, then drop

Posted: 13 Jul 2015, 20:01
by BGM
jballi just started a thread here (in case anyone stumbles upon this one): ... 236#p49236

Re: [how to] simulated drag, then drop

Posted: 06 Mar 2016, 10:37
by beeski
thank you for the heads up! :)