I've learned how to use controlclick, controlsend.
But i find it really hard to make a search image in an area in an inactive window with using bitmapfromhwnd , not bitmapfromscreen, since i want it to be off screen searching.
I've tried merging scripts from some posts, i can run the script, but still can not to find the image:
https://www.autohotkey.com/boards/viewtopic.php?t=17507
https://www.autohotkey.com/boards/viewtopic.php?t=38324
https://www.autohotkey.com/boards/viewtopic.php?p=23210#p23210
Here's my code:
Code: Select all
#NoEnv
ListLines, Off
SetBatchLines, -1
Process, Priority,, High
#Include GDIP.ahk
#Include Gdip_ImageSearch.ahk
OnExit, EXIT_LABEL
winTarget := "Untitled.png - Paint"
needleDirA:= "C:\Users\MyUserName\Desktop\ahk studies\test image\circle paint.png"
CustomImgSearch(ByRef out1, ByRef out2, x1, y1, x2, y2, needleDir, vari=0, trans="",direction=5)
{
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
bmpNeedle := Gdip_CreateBitmapFromFile(needleDir)
bmpHaystack := Gdip_BitmapFromHWND(hwnd := WinExist(winTarget)) ;you need the handle of the window to search in
found := Gdip_ImageSearch(bmpHaystack,bmpNeedle,tempxy,x1,y1,x2,y2,vari,trans,direction)
if !( found < 1 ) ; if successful
{
out:=StrSplit(tempxy,"`,")
out1:=out[1] + x1
out2:=out[2] + y1
}
Gdip_DisposeImage(bmpHaystack)
Gdip_DisposeImage(bmpNeedle)
Gdip_Shutdown(pToken)
return ( found < 1 ) ; will return 0 for SUCCESS, 1 for FAILURE
}
F4::
{
if (!CustomImgSearch(OutputX,OutputY, 676, 244, 1126, 590,needleDirA)) ; got the image
{
ControlClick, x%OutputX% y%OutputY%, %winTarget%
Msgbox %winTarget%,%OutputX%,%OutputY%,%fileDir%
}
else
{
Msgbox Image not found : %needleDirA%, %winTarget%,%OutputX%,%OutputY%
return
}
return
}
esc::
EXIT_LABEL:
Gdip_Shutdown(pToken)
EXITAPP