berkoma Posted April 1, 2014 Posted April 1, 2014 Hello again all. I've found the autoIt Help file is amazing at answering questions, however I have not been able to find any documentation there for _ImageSearchArea. My google results have been just as unsuccessful so I'm hoping someone can help me understand how it works by providing a couple of concrete examples. So, would someone be able to show me a couple of examples, such as 1) If my desktop is 1024 x 768 and I want to search only the top half of the desktop area for an image called blue_btn.png, what would that look like. 2) If my desktop is 1024 x 768 and I want to search only the left half of the desktop area for an image called blue_btn.png, what would that look like. 3), lastly, if my desktop is 1024 x 768, and I want to constrain the search to a box that is centered and is 800 wide by 400 tall (for the same image as above). I would be extremely thankful to anyone who can provide such example or can at least point me to some tutorial that would demonstrate how to do them.
Moderators JLogan3o13 Posted April 1, 2014 Moderators Posted April 1, 2014 What exactly are you trying to accomplish (I can throw out a wild guess you want to click on a blue button)? 90% of the time, there is a much easier way of doing things than using pixelsearch or imagesearch functions. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
jdelaney Posted April 1, 2014 Posted April 1, 2014 (edited) Example of looping through the 'icons' on your desktop: #include <GuiListView.au3> #include <Array.au3> $h1 = WinGetHandle("[CLASS:Progman]") $h2 = ControlGetHandle($h1,"","[CLASS:SysListView32; INSTANCE:1]") $i1 = _GUICtrlListView_GetItemCount($h2) For $i = 0 To $i1 - 1 $s = _GUICtrlListView_GetItemText($h2,$i) $a = _GUICtrlListView_GetItemPosition($h2,$i) ConsoleWrite($s & " " & _ArrayToString($a) & @CRLF) Next You can add whatever logic you want to that. Edited April 1, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
berkoma Posted April 2, 2014 Author Posted April 2, 2014 Well in this case it's basically a chat client lets say. When someone messages you I want it to click accept. Currently it scans the entire desktop, like so: ;Press accept function ---------------------------------------------------------- Func pressAccept() Local $result = _ImageSearch("pics/login/accept_btn.png", 1, $x, $y, 90) If ($result == 1) Then MouseClick("left", $x, $y, 1) EndIf EndFunc ;Press accept function ---------------------------------------------------------- In this case, the accept or decline box (area where the button appears) is roughly located in an area from the center 800 wide by 400 tall, so I only want to scan that area for the accept button, instead of scanning the whole 1024 x 768. From what I understand, _ImageSearchArea should allow me to constrain my image search to this area, I just don't understand how to make it do so. Also, there is no new process or window activated, it's just a popup (I don't know if its java or what, but nothing new comes up in the task manager) so I'm really just trying to optimize what I'm doing now by narrowing down the area that it searches for this specific button
jdelaney Posted April 2, 2014 Posted April 2, 2014 (edited) If you see a window, or a popup, or anything, it has a handle associated. Use the AutoIT window info tool on it, and post the information from the summary tab. If it is a java app, then you probably won't be able to interact with the window easily (outside of relative clicks, or controlsend), but the first step is getting the window. Edited April 2, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Solution berkoma Posted April 5, 2014 Author Solution Posted April 5, 2014 Yeah, like I said, there is no separate window, it is integrated into the client. I was able to solve this with some help from another board though, so I'll post the solution here in case someone else needs it. The first step, was to define a couple of variables: $centerX = @DesktopWidth * 0.5 $centerY = @DesktopHeight * 0.5 This simply uses AutoIt's built in macros (@DesktopWidth and @DesktopHeight) to define the "halfway point" of both the horizonal (X) and vertical (Y) axis's Once I had a reference point, I could work backward or forward from those centers on both axis to limit my search area like so: ;Press accept function ---------------------------------------------------------- Func pressAccept() Local $result = _ImageSearchArea("pics/login/accept_btn.png", 1, $centerX -150, $centerY -70, $centerX +150,$centerY +70,$x, $y, $tol) If ($result == 1) Then MouseClick("left", $x, $y, 1) EndIf EndFunc ;Press accept function ---------------------------------------------------------- So this is now limiting my search area to 150px in each direction (left and right) from the center of X and 70px in each direction (up and down) from the center of Y.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now