A Simple Drag n Drop Script Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
hamidrana085
Posts: 15
Joined: 05 Jun 2023, 00:30

A Simple Drag n Drop Script

Post by hamidrana085 » 05 Jun 2023, 00:40

Hi, I'm new to AutoHotKey. I just want to write a function that simply drags and drops the latest downloaded file (which sits at a constant position in Chrome) to be dragged and dropped into After Effects which is already open.
I wrote this and as you can guess, it doesn't work for some reason:

Code: Select all

MouseMove 103, 1022
Send "{LButton down}"
Sleep 100
MouseMove 103, 900
Sleep 100
WinActivate ("ahk_exe AfterFX.exe")
Sleep 100
Send "{LButton up}"
Last edited by Ragnar on 05 Jun 2023, 00:45, edited 1 time in total.
Reason: code tags

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: A Simple Drag n Drop Script

Post by boiler » 05 Jun 2023, 01:47

For one thing, remove the space before the open parenthesis in your WinActivate line, or leave the space and remove the parentheses.

I assume those are meant to be screen coordinates, but you haven’t used CoordMode to specify that, so they would be relative to the active window.

It seems odd that you are activating a window in the middle of a drag. That typically doesn’t happen when a manual drag occurs, so maybe Windows won’t react as it typically would.

hamidrana085
Posts: 15
Joined: 05 Jun 2023, 00:30

Re: A Simple Drag n Drop Script

Post by hamidrana085 » 05 Jun 2023, 02:01

@boiler
Even leaving that window changing part, the Drag only doesn't work this way. Like if I were to simply click n drag the downloaded file upwards in Chrome, it opens the file in Chrome. I can't even do this in this way. The file doesn't simply follow the cursor. The only way I managed to make the file follow the cursor is using SendEvent "{Click 103 900}". But again, I can't use Alt+Tab or WinActivate in the middle of SendEvent execution.

Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: A Simple Drag n Drop Script

Post by Rohwedder » 05 Jun 2023, 02:02

Hallo,
perhaps (untested)?:

Code: Select all

MouseClickDrag "Left", 103, 1022, 103, 900, 5

hamidrana085
Posts: 15
Joined: 05 Jun 2023, 00:30

Re: A Simple Drag n Drop Script

Post by hamidrana085 » 05 Jun 2023, 02:05

Rohwedder wrote:
05 Jun 2023, 02:02
Hallo,
perhaps (untested)?:

Code: Select all

MouseClickDrag "Left", 103, 1022, 103, 900, 5
Yeah that was my first attempt. But the file simply doesn't follow along the cursor. Can you test it for me tho? I mean, just download any image in Chrome and try and open it this way.

Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: A Simple Drag n Drop Script

Post by Rohwedder » 05 Jun 2023, 02:32

I tried this to drags and drop the downloaded image from Chrome (1. Monitor) to Pain.Net (2. Monitor), it works!

Code: Select all

#Requires AutoHotkey v2.0
q::
{
	CoordMode "Mouse", "Screen"
	MouseClickDrag "Left", 148, 978, 1914, 325, 5
}

hamidrana085
Posts: 15
Joined: 05 Jun 2023, 00:30

Re: A Simple Drag n Drop Script

Post by hamidrana085 » 05 Jun 2023, 03:39

Rohwedder wrote:
05 Jun 2023, 02:32
I tried this to drags and drop the downloaded image from Chrome (1. Monitor) to Pain.Net (2. Monitor), it works!

Code: Select all

#Requires AutoHotkey v2.0
q::
{
	CoordMode "Mouse", "Screen"
	MouseClickDrag "Left", 148, 978, 1914, 325, 5
}
Yeah that seems fine to move it from one monitor to another. But I need a way to Switch between windows in between without breaking the dragging. For example, using SendEvent Up and Down almost does the job, but if I put anything to Switch windows in between them, the dragging breaks. :(

Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: A Simple Drag n Drop Script  Topic is solved

Post by Rohwedder » 05 Jun 2023, 05:46

Why do you need a way to switch between windows? Is your chrome window perhaps covering the target window?
Then maybe this example that works for me:
Chrome and Paint.Net below it, both maximized on my 1st monitor. WinSetRegion makes a hole in Chrome so the drag and drop there can drop the image on Paint.Net.

Code: Select all

#Requires AutoHotkey v2.0
q::
{
	WinGetPos &X, &Y, &Width, &Height, "ahk_exe chrome.exe"
	WinSetRegion "0-0 0-" Height " " Width "-" Height " " Width "-0 0-0 200-200 400-200 400-400 200-400 200-200"
	, "ahk_exe chrome.exe"
	MouseClickDrag "Left", 148, 978, 300, 300, 5
	WinSetRegion , "ahk_exe chrome.exe"
}
Edit: In the WinSetRegion command Width and Height had been interchanged.
Last edited by Rohwedder on 06 Jun 2023, 02:31, edited 1 time in total.

hamidrana085
Posts: 15
Joined: 05 Jun 2023, 00:30

Re: A Simple Drag n Drop Script

Post by hamidrana085 » 06 Jun 2023, 00:36

Rohwedder wrote:
05 Jun 2023, 05:46
Why do you need a way to switch between windows? Is your chrome window perhaps covering the target window?
Then maybe this example that works for me:
Chrome and Paint.Net below it, both maximized on my 1st monitor. WinSetRegion makes a hole in Chrome so the drag and drop there can drop the image on Paint.Net.

Code: Select all

#Requires AutoHotkey v2.0
q::
{
	WinGetPos &X, &Y, &Width, &Height, "ahk_exe chrome.exe"
	WinSetRegion "0-0 0-" Width " " Height "-" Width " " Height "-0 0-0 200-200 400-200 400-400 200-400 200-200"
	, "ahk_exe chrome.exe"
	MouseClickDrag "Left", 148, 978, 300, 300, 5
	WinSetRegion , "ahk_exe chrome.exe"
}
Holly smoke that's smart. Had to make some adjustments, but got it working. You saved a ton of my time and work. Can't thank you enough man.

Post Reply

Return to “Ask for Help (v2)”