Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
883 views
in Technique[技术] by (71.8m points)

autohotkey - Script modification(drag and drop)

I have simple script that looks for specified color pixel in restricted area then performs move mouse of this pixel to specified x,y coordinates it looks like this(control hold is added, because it needs to be pressed while moving stock):

#ifwinactive
F10::
PixelSearch, ItemX, ItemY, 1800, 600, 1700, 500, 0xFFE047, 1 , RGB FAST
if ErrorLevel = 0
Mousemove, ItemX, ItemY, 0
Send, {lbutton down}
sleep, 20
Send, {lctrl down}
Random x, 1600, 1700
Random y, 590, 655
Mousemove, x, y, 0
Send, {lbutton up}
Send, {lctrl up}
return

It works great but takes control over my MOUSE which I don't want, so I am trying to modify it to perform action without taking control over my mouse. I have tried to search, using controlclick but this couldn't handle dragging, then I have read about PostMessage which I don't clearly understand but I have come with this kind of script(not fully understand dll calls that's why most likely it doesn't work like intented):

#ifwinactive

x := 1650
y := 620

F10::
PixelSearch, ItemX, ItemY, 1900, 600, 1750, 500, 0xFFC661, 1, RGB Fast 
CoordMode, Pixel, Screen
if !hWnd := DllCall("WindowFromPoint", Int,ItemX, Int,ItemY, Ptr)
if !hWnd := DllCall("WindowFromPoint", UInt64,(ItemX&0xFFC661)|(ItemY<<32), Ptr)
if !hWnd := DllCall("WindowFromPoint", UInt64, x|(y << 32), Ptr)
    return
VarSetCapacity(POINT, 8, 0)
NumPut(ItemX, POINT, 0, "Int"), NumPut(ItemY, POINT, 4, "Int")
DllCall("user32ScreenToClient", Ptr,hWnd, Ptr,&POINT)
ItemX := NumGet(POINT, 0, "Int"), ItemY := NumGet(POINT, 4, "Int")
if ErrorLevel
PostMessage, 0x0200, 0, ItemX&0xFFC661|ItemY<<16,, % "ahk_id " hWnd         ;WM_MOUSEMOVE
sleep, 5
PostMessage, 0x0201, 0, ItemX&0xFFC661|ItemY<<16,, % "ahk_id " hWnd         ;WM_LBUTTONDOWN
sleep, 5
PostMessage, 0x0200, 0, x|y<<16,, % "ahk_id " hWnd      ;WM_MOUSEMOVE
sleep, 5
PostMessage, 0x0202, 0, x|y<<16,, % "ahk_id " hWnd               ;WM_LBUTTONUP
sleep, 5
return

There is problem with this scirpt it actually act like this: Search for pixel>if it's there>perform post messages under my cursor(actually taking things under my mouse to specified x,y. While what I want is to look for pixel, pick this pixel and move it. Is it even possible without taking control over my mouse?

EDIT! NEW CODE

#ifwinactive

CoordMode, Pixel , Screen

x := 1650
y := 620
lparam := pX | (pY << 16)
lparam2 := x | (y << 16)

f10::
PixelSearch, pX, pY, 1900, 1000, 1750, 500, 0xFFE047, 1, Fast 
if Errorlevel
{
PostMessage, 0x0200, 0, %lparam%,, ahk_exe something.exe        ;WM_MOUSEMOVE
sleep, 10
PostMessage, 0x0201, 0x0001, %lparam%,, ahk_exe something.exe          ;WM_LBUTTONDOWN
sleep, 10
PostMessage, 0x0200, 0x0001, %lparam2%,, ahk_exe something.exe      ;WM_MOUSEMOVE
sleep, 10
PostMessage, 0x0202, 0, %lparam2%,, ahk_exe something.exe                ;WM_LBUTTONUP
}
return
question from:https://stackoverflow.com/questions/65882948/script-modificationdrag-and-drop

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...