Efie
Efie

Reputation: 1680

AHK ControlClick and drag?

I created a script for AHK using ControlClick rather than regular mouse events so that I can keep using my mouse to do other tasks while I run the script. However, I need to simulate a mouse click and drag event. Is it possible to do this using the ControlClick event?

I tried using:

ControlClick, x365 y560, SM N910V,,,,D
ControlClick, x365 y770, SM N910V,,,,U

but with no luck.

Upvotes: 3

Views: 1977

Answers (1)

nelsontruran
nelsontruran

Reputation: 554

Unfortunately this functionality is not available out of the box due to how ControlClick works. It can be accomplished with a COM call (if you are click & dragging a files to a window for example). I can't remember where I found this online, but pretty sure it was on the AHK forum.

;window = target window, standard AHK window syntax works eg: ahk_id hwnd or just WinTitle
;files = list of files to be dropped
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)
}

If you give specifics of what you are clicking and dragging, I could probably give you a much easier work-around.

Upvotes: 1

Related Questions