Developers Jos Posted May 27, 2017 Developers Posted May 27, 2017 So don't make these comments in an unrelated thread please. If you have something to tell me about a closed thread you can PM me. For the record: I have deliberately closed that other thread as way too many people felt the urge to post a reply while they should know better. So discussion stops here and back on topic for this thread! Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
junkew Posted May 27, 2017 Posted May 27, 2017 Maybe gdi functions can help further besides pixelsearch. See for example It gives the functions to have all pixels and colors in an array and references to other gdi functions. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
tonycst Posted May 29, 2017 Author Posted May 29, 2017 (edited) On 5/27/2017 at 1:12 AM, Jos said: The windowname is NOT the same as a Window Handle! So keep on reading that helpfile how to get the window handle for the specified windowname! Jos Please look into my last post and into the code i posted. I use window handle instead of the title. Result is exactly the same. It searches DESKTOP instead of window provided by either handle or by window name. No difference. Must be a bug. Or give me one simple example on how to search specific color in a specific window. :Thanks junkeW But i dont want to go into more complicated function not being able to get the simple one working. Edited May 29, 2017 by tonycst forgot to menton someone else
tonycst Posted May 29, 2017 Author Posted May 29, 2017 (edited) OK I Identified the problem. Windows Photo Viewer was to blame. When would preview the image using it, it will not pick find the color. One i opened that image with MS Paint, it worked. Is this a BUG or what ? I also found that when using window handle, coordinates are not corresponding to that window, but to the desktop. For example: PixelSearch($X,$Y,200,400, $PixelColor, 2, 1,$WindowHandle) If window is located on the DESKTOP in given coordinates, then it will find the color. But the 200,400 should be relative to the window, but they are relative to the desktop coordinates, not to the window coordinates. PixelSearch($X,$Y,$X+200,$Y+400, $PixelColor, 2, 1,$WindowHandle) This code will search the window based on window location (which is what we all want) how ever, the fact that it does not search coordinates related to the window but to the desktop, i had to add the area of search to the window position. This has to be a bug because it does not make sense to take window location into consideration when you provide search area (not the search startinglocation) The search starting location are the first two parameters of the function The search area are the second two parameters of the function. It is the second parameter that does not work in any logical sense. It needs to be relative to what ever window its seaching. If it searches desktop, then make it relative to desktop. Edited May 29, 2017 by tonycst
jchd Posted May 29, 2017 Posted May 29, 2017 It's however pretty clear that WinGetPos returns the position of the up-left corner and the window dimensions, while PixelSearch requires the absolute position of the up-left and down-right corners of the area to search. The only bug here is not reading the functions' specifications. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
InnI Posted May 29, 2017 Posted May 29, 2017 7 hours ago, tonycst said: I also found that when using window handle, coordinates are not corresponding to that window, but to the desktop. To use the window handle, you need to switch the option PixelCoordMode to 0 or 2 Opt("PixelCoordMode", 0) ; relative coords to the defined window ; or Opt("PixelCoordMode", 2) ; relative coords to the client area of the defined window
tonycst Posted June 7, 2017 Author Posted June 7, 2017 (edited) On 5/29/2017 at 2:45 AM, InnI said: To use the window handle, you need to switch the option PixelCoordMode to 0 or 2 Opt("PixelCoordMode", 0) ; relative coords to the defined window ; or Opt("PixelCoordMode", 2) ; relative coords to the client area of the defined window AHA ! thank you ! DIdnt see that in the help file. It was under "Relative" Otherwise i would not be here asking stupid questions to begin with. I learned to look into that category as well. Wouldnt it be AMAZING if once Window handle is provided, then automatically set option to 0 ? I mean what other purpose of providing window handle would there be if not using coordinates relative to that window. What is the difference between 0 = relative coords to the defined window 2 = relative coords to the client area of the defined window ?????????????????????? I am not sure what does "client area" mean Edited June 7, 2017 by tonycst
tonycst Posted June 7, 2017 Author Posted June 7, 2017 OK i updated the code and its weird. Still not as expected. Opt("WinTitleMatchMode", 2) $WindowToSearch = "0.jpg" $PixelColor = 0x6FDD00 ;lime green Opt("PixelCoordMode", 1) While 1 If WinExists ($WindowToSearch) = 1 Then $WindowHandle = WinGetHandle ($WindowToSearch) $WinPos = WinGetPos ($WindowToSearch) $Search = PixelSearch(0,0,200,400, $PixelColor, 2, 1,$WindowHandle) ;2 for shade variation,1 for steps, and window name to search If IsArray($Search) = True Then ConsoleWrite (@CRLF & "Found it at X=" & $Search[0]& " Y=" & $Search[1]) sleep (100) Else ConsoleWrite (@CRLF & "nothing found " & $WindowHandle) sleep (100) Endif Else ConsoleWrite (@CRLF & "Loking for window") sleep (100) EndIf Wend Its still searching RELATIVE TO DESKTOP and not to the hWnd ALSO: It searches way way way outside of dimension. 200x400 it says but it searches FAR beyond all the way to the bottom of 1920x1080 screen, and stops finding it half way to the right, which is 1920/2=960. All the way before half the screen, it will find it. PixelSearch returns number for coordinates as if the found pixel is within specified area. Moving window around changes where PixelSearch finds the color, indicating that its NOT searching the window, but DESKTOP as i said MULTIPLE times here before. Function is clearly bugged.
Danp2 Posted June 7, 2017 Posted June 7, 2017 You still have this in your code Opt("PixelCoordMode", 1) Latest Webdriver UDF Release Webdriver Wiki FAQs
tonycst Posted June 29, 2017 Author Posted June 29, 2017 (edited) On 6/7/2017 at 4:14 AM, Danp2 said: You still have this in your code Opt("PixelCoordMode", 1) HAHA i got it. But changing it to 0 does not help. It still looking in the wrong place like before. This is the code Opt("WinTitleMatchMode", 2) $WindowToSearch = "0.jpg" $PixelColor = 0x6FDD00 ;lime green Opt("PixelCoordMode", 0) ;search based on window position While 1 If WinExists ($WindowToSearch) = 1 Then $WindowHandle = WinGetHandle ($WindowToSearch) $WinPos = WinGetPos ($WindowHandle) $R = $WinPos[0] ;window position in X $B = $WinPos[1] ;window position in Y $Search = PixelSearch(0,0,200,400, $PixelColor, 2, 1, $WindowHandle) ;2 for shade variation If IsArray($Search) = True Then ConsoleWrite (@CRLF & "Found it at X=" & $Search[0]& " Y=" & $Search[1] & " WinPos " & $R & " " & $B & " ") sleep (100) Else ConsoleWrite (@CRLF & "nothing found " & $WindowHandle) sleep (100) Endif Else ConsoleWrite (@CRLF & "Loking for window") sleep (100) EndIf Wend The only way i make it work is if i utilize wingetpos to get window position and then add search area. Look at this line $Search = PixelSearch(0,0,$R+200,$B+400, $PixelColor, 2, 1, $WindowHandle) ;2 for shade variation Thats what makes this code work. Clearly function is bugged. It searches relative to desktop no matter what you do, unless i force it to search based on window position and then addidng search area. All i have to do is to specify search area. But because functions bugged, i also have to point it to the window position first because its not searching based on window position otherwise as the help file states. Opt("PixelCoordMode", 0) Does not work. Its that simple. Not to mention: who even tried test the code using the scenario i described ? NO ONE. Edited June 29, 2017 by tonycst
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