AC130 Posted May 18, 2011 Posted May 18, 2011 Is there anyway to search for a pixel in a application instead of my whole desktop or xxxx by xxxx. Like i want to search for pixel 0x000000 in a program called "lol" idk rofl...
monoscout999 Posted May 18, 2011 Posted May 18, 2011 when you uses pixelsearch you define the area to search... :S look it in the help file... now if you want to get the area of a specific windows use _WinAPI_GetClientRect()function look in the help example how to use it
kaotkbliss Posted May 18, 2011 Posted May 18, 2011 WinGetPos will also do this it gives you the x,y of the upper left corner as well as the width and height of the window. So your your upper left of the search would be x,y and your lower right corner would be x+width,y+height $pos=WinGetPos("lol") $search=PixelSearch($pos[0],$pos[1],$pos[0]+$pos[2],$pos[1]+$pos[3],0x000000) 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
monoscout999 Posted May 18, 2011 Posted May 18, 2011 WinGetPos will also do this it gives you the x,y of the upper left corner as well as the width and height of the window. So your your upper left of the search would be x,y and your lower right corner would be x+width,y+height $pos=WinGetPos("lol") $search=PixelSearch($pos[0],$pos[1],$pos[0]+$pos[2],$pos[1]+$pos[3],0x000000) that´s better than mine
Moderators SmOke_N Posted May 18, 2011 Moderators Posted May 18, 2011 Is there anyway to search for a pixel in a application instead of my whole desktopPixelCoordMode:Sets the way coords are used in the pixel functions, either absolute coords or coords relative to the window defined by hwnd (default active window):0 = relative coords to the defined window1 = absolute screen coordinates (default)2 = relative coords to the client area of the defined windowWhen you use the AutoItInfo tool to get the coordinates you want to search, you make sure you change it to Client coord mode ( Options -> Coord Mode -> Client ).If you're only ever going to use client coord mode, at the top of your script you use:Opt("PixelCoordMode", 2)And use the handle to the window you want to use in PixelSearch() / PixelGetColor() ( last parameter usually ). Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Moderators SmOke_N Posted May 18, 2011 Moderators Posted May 18, 2011 ok heres what Im trying to do: when i press my "find" button on my gui, i want it to move the mouse to a program called "lol" Then I want it to search for a pixel (0x00000) in the program (lol) once its found i want it to msgbox " you have the pixel" here what i have so far: Case $Find WinActivate ( "lol" ) $Pixel1 = PixelSearch ( 0, 0, @programcalledlol, @programcalledlol, 0x000000) Yeah, we get a lot from that I mean, other than the fact that you're trying to use a macro ( @ ) that doesn't exist, and of course it fails. To move the mouse, look at the help file for Mouse* functions. To get Coordinates, look at Win* functions. When/If what you do fails, put something together that someone could run from their desktop replacing your app/window name with their own. Then post for help. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
monoscout999 Posted May 18, 2011 Posted May 18, 2011 (edited) Is there a way to pixelsearch half of an application. like i have a program called "lol" and its 500 x 500. i want it to search "lol" by 250 x 250 for a pixel, instead of it searching the whole program. hope im putting it right yes ... using maths... you have to know where to search... when you call pixelsearch() func.. you have to put the coords of a recttangle area... 4 points.. the pixelsearch() func search inside that area the color you want and return an arrat variable.. look.. for search in a square area who starts in the top left of the screen and have 250 pixels of width and 250 pixels of height $colorfound = pixelsearch(0,0,250,250,0xFFFFFF) If NOT @error then msgbox(0,"pixel found!",The pixel is on the "&$colorfound[0]$" of X coord, and "&$colorfound[1]&" of coord Y") else msgbox(0,"pixel NOT found", "the color has not found") endif sorry my bad english... in a while i put the example to look in your windows.... EDIT comming..... well ... reading your post what you want is this.. $pos=WinGetPos("lol") winactivate("lol") $search=PixelSearch($pos[0],$pos[1],$pos[0]+$pos[2],$pos[1]+$pos[3],0x000000) If NOT @error then msgbox(0,"pixel found!",The pixel is on the "&$search[0]$" of X coord, and "&$search[1]&" of coord Y") else msgbox(0,"pixel NOT found", "the color has not found") endif if you want to search a partial part use maths and brain is not so hard.... i can{t explaint it better because i don´t know how to say it on english... but men is not so hard.. you have to define four points only... be cleaver use maths and brain Edited May 18, 2011 by monoscout999
Blue_Drache Posted May 19, 2011 Posted May 19, 2011 In one of my programs, I generally search for a colour across a wide zone, and once I get a match I zoom in my search zone to a 50x50 area and scan it again for a change. Once it changes, I have it do something else. It's much faster for me to do it that way. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
monoscout999 Posted May 19, 2011 Posted May 19, 2011 ok lol im having another problem with this. the programs size is 1000 x 1000 and its called "lol" and what im trying to do is that when my 1st checkbox is checked it will search that program (lol) for a pixel (0x000000) in area 250 x 750 and then msgbox pixel is found.... and if the 2nd checkbox is checked, then i want it to search that program (lol) for a pixel in area 500 x 750 and msgbox pixel is found. Case $Find If $CheckBox = 1 Then WinActivate ( "lol" ) Do $Pixel2 = PixelSearch ( 250, 750, 1000, 1000, 0x000000) Until Not @Error MsgBox ( Pixel found ) Else WinActivate ( "lol" ) Do $Pixel2 = PixelSearch ( 500, 750, 1000, 1000, 0x000000) Until Not @Error MsgBox ( Pixel Found) ; I know that msgbox is wrong, i just setting example. EndIf hope im putting this right lol... two things... use tidy toll before posting is much easier to look the script that way... the second is a question... are you complety sure that the area that you define for the pixelsearch function is what you want?? the four values are for 2 points to do a rectangle on the screen. x500 - y700 is one point the other is 1000x - 1000y ¿is that what you want?
monoscout999 Posted May 19, 2011 Posted May 19, 2011 (edited) another thing... pixelsearch will give you the first pixel that it found... in other words the most left and topest inside the area you gave it Edited May 19, 2011 by monoscout999
Developers Jos Posted May 19, 2011 Developers Posted May 19, 2011 anybodyssss. Better learn to be patient ..... and one word about the true nature of your question and you will face consequences. 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.
Developers Jos Posted May 19, 2011 Developers Posted May 19, 2011 hmm nevermind i think i got it working Don' understand where you got the impression I was joking.... 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.
Blue_Drache Posted May 19, 2011 Posted May 19, 2011 (edited) Is that a Switch/Case block or Select/Case block? Your syntax is wrong, regardless of which one it is. Case $Find ... what is it supposed to be? 1? 0? 10,000? "Sum dum string"? You also have a complete misunderstanding of how PixelSearch() works as demonstrated by your request and example code. A 250x750 square can be ANYWHERE inside your original 1,000x1,000, right? So I'm assuming you either have a general detection method, or you know approximately where something appears all the time. #RequireAdmin Opt("WinTitleMatchMode", 4) Opt("MustDeclareVars", 1) Local $hwndLOL = WinGetHandle("LOL") Local $iaClientSize = WinGetClientSize($hwndLOL) Local $iStartX = Default, $iStartY = Default, $iaPixel = Default Local $bFind = True Local $iCheckBox Select Case $bFind = True If $iCheckBox = 1 Then WinActivate($hwndLOL) Do $iaPixel = PixelSearch($iStartX, $iStartY, $iStartX + 250, $iStartY + 750, 0x000000, Default, Default, $hwndLOL) Until Not @error If IsArray($iaPixel) Then ConsoleWrite("Found the first Pixel at X: " & $iaPixel[0] & "Y: " & $iaPixel[1] & @CRLF) EndIf Else WinActivate($hwndLOL) Do $iaPixel = PixelSearch($iStartX, $iStartY, $iStartX + 500, $iStartY + 750, 0x000000, Default, Default, $hwndLOL) Until Not @error If IsArray($iaPixel) Then ConsoleWrite("Found the second Pixel at X: " & $iaPixel[0] & "Y: " & $iaPixel[1] & @CRLF) EndIf EndIf EndSelect Work with window handles. They're more reliable and they never change. Learn Cartesian coordinates and how to work with relative coordinate systems. In my example, your $iStartX and $iStartY can be anywhere inside your orignal 1,000x1,000 square and the program will draw an imaginary box from that point. Why am I grabbing the client size? Perhaps for a check later on before I draw the bounding box to see if I'm going to search outside the window. I can shave off time if I don't have to check pixels that don't exist. I completely fill out the PixelSearch parameters because I want to ensure I'm only searching inside the window I want to search. My variable names tell you what they are. "$hwndVariable" is a WINDOW HANDLE, "$iVariable" is an INTEGER... "$fVariable" is a FLOAT... "$bVariable" is a BOOLEAN (true/false) or BINARY (1/0) (same idea really)... and "$sVariable" is a STRING. You get the idea. Also ... having an infinite loop until some condition is true without a means to escape the loop is silly. You may want to look into that. Edited May 19, 2011 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
AC130 Posted May 19, 2011 Author Posted May 19, 2011 oo goodness ill try that then i never even thought about that it searches anywhere lol..
monoscout999 Posted May 19, 2011 Posted May 19, 2011 (edited) hmm nevermind i think i got it working $Pixel2 = PixelSearch ( 250, 750, 1000, 1000, 0x000000)im guessing this was the right thing.doesn't this mean that its searching 1000 x 1000 ( the program size) for a pixel in rectangle 250 x 750?nothink about this... ¿how many data need to find a point on a 2d plane?(sorry my bad english)¿how many points need to do a rectangle?Inside that rectangle pixelsearch will try to find a color pixel that you define(0x000000) pixelsearch will give you the firs pixel whit the color 0x000000 that find..... startinf his finding from left to right from top to bottom :S im going mad if you know where is the point you have to be more specific about what you want Edited May 19, 2011 by monoscout999
AC130 Posted May 19, 2011 Author Posted May 19, 2011 (edited) Case $Find If GUICtrlRead($CheckBox1) = 1 Then WinActivate ( "LOL" ) Do $Pixel2 = PixelSearch ( 378, 122, 1000, 1000, 0x000000) Until Not @Error MsgBox ( DEMO1 ) Else WinActivate ( "LOL" ) Do $Pixel3 = PixelSearch ( 422, 123, 1000, 1000, 0x000000) Until Not @Error MsgBox ( Demo2 ) EndIf Ok this is working other than the fact that if the checkbox2 is checked it still says "demo 1". im trying to get it so that when checkbox1 is checked it says demo 1 and when checkbox2 is checked it says demo 2. also the coordinates are exact. i want it to search for 0x00000 at point 422, 123 in the program lol when checkbox 1 is checked and so on any help? thanks in advance. Edited May 19, 2011 by AC130
AC130 Posted May 19, 2011 Author Posted May 19, 2011 Overview: When I press my "Find" button, I want it to check to see if CheckBox1 is checked, if it is checked, I want it so search for pixel 0x000000 in location 378,122 in a 1000 x 1000 program, and then msgbox "Pixel1 Found" If Checkbox2 is checked, then I want it to search for pixel 0x000000 in location 422,123 in a 1000 x 1000 program, and then MsgBox "Pixel2 Found". I've tried my hardest to get this working, and this will definetely be the last time I need help. Sorry for so many posts, but thank you for helping.
AC130 Posted May 20, 2011 Author Posted May 20, 2011 (edited) #RequireAdmin Opt("WinTitleMatchMode", 4) Opt("MustDeclareVars", 1) Local $hwndLOL = WinGetHandle("LOL") Local $iaClientSize = WinGetClientSize($hwndLOL) Local $iStartX = Default, $iStartY = Default, $iaPixel = Default Local $bFind = True Local $iCheckBox Select Case $bFind = True If $iCheckBox = 1 Then WinActivate($hwndLOL) Do $iaPixel = PixelSearch($iStartX, $iStartY, $iStartX + 250, $iStartY + 750, 0x000000, Default, Default, $hwndLOL) Until Not @error If IsArray($iaPixel) Then ConsoleWrite("Found the first Pixel at X: " & $iaPixel[0] & "Y: " & $iaPixel[1] & @CRLF) EndIf Else WinActivate($hwndLOL) Do $iaPixel = PixelSearch($iStartX, $iStartY, $iStartX + 500, $iStartY + 750, 0x000000, Default, Default, $hwndLOL) Until Not @error If IsArray($iaPixel) Then ConsoleWrite("Found the second Pixel at X: " & $iaPixel[0] & "Y: " & $iaPixel[1] & @CRLF) EndIf EndIf EndSelect OK i tried your code, but it wont work. even if i have the checkbox checked it wont do anything.... Edited May 20, 2011 by AC130
monoscout999 Posted May 20, 2011 Posted May 20, 2011 (edited) Overview: When I press my "Find" button, I want it to check to see if CheckBox1 is checked, if it is checked, I want it so search for pixel 0x000000 in location 378,122 in a 1000 x 1000 program, and then msgbox "Pixel1 Found" If Checkbox2 is checked, then I want it to search for pixel 0x000000 in location 422,123 in a 1000 x 1000 program, and then MsgBox "Pixel2 Found". I've tried my hardest to get this working, and this will definetely be the last time I need help. Sorry for so many posts, but thank you for helping. you stll don´t get it.... maybe if you ewxplain better what you want to do... why you need to find that pixel.. For check the checkboxes you should use Guictrlgetstate() function and see the help file and the examples to figure out how to use it.. About pixelsearch area... please try to lear this well... if you can take a snapshot from the window that you want to get the pixel and mark the area somehow to show us.. it will be more helpful you always say the aplication window have a area size of 1000X1000 but you dont start to find in the point 0x0 so you start from 422X123, so the another point to cover the whole window aerea will be 1422X1123.. paint again Let`s say the 1 entire draw is your monitor... 2 the blue box is your program... 3 the red square is the place you want to find... to define the area for pixelsearh() function you need 4 data to define 2 points 1 the first data is the left side of the area... in this case 0 2 the second data is the top side of the area... in this case 0 3 the thirs data is the right side of the area.... in this case 1000 4 the fourth data is the bottom side of the area... in this case 1000 but ¿what happend when the program window is not doked on the top left side of the monitor? let`s say is a distance of 10 pixeles from the left of the monitor and 10 pixels from the top of the monitor.... ¿are the data we use before the same for this window? The answer is NO... Paint again so what is the area of the window that we use here... the first data in NOT 0 anymore because the window start in the 10 pixel from the left... so... 1 the first data is 10 (left) the distance between the windows edge and the monitor edge 2 the second data is 10(top) the distance between the windows edge and the monitor edge 3 The third data is 1010(right) this became from the sum of the left side data and the windows widht 3 The third data is 1010(right) this became from the sum of the top side data and the windows height now... with autoit is a function that get for you the left, top, width and height data of any window with this data and a little math you can get the area of the window the function gives you the first and second data, you need the other two.. as we already says the tirhd data is a sum of the first data and the widht... we have bout... so we only need to do the sum the same with the fourt... the function is wingetpos() and this function will return to you an array variable for ex $pos = wingetpos("lol") will return $pos[0] ; the left distance $pos[1] ; the top distance $pos[2] ; the windows widht $pos[3] ; the windows height I hope you understand this way... my fear is that your pixelsearch function is getting something that is not what you want... i think that you can do it on your own right now... dont say i dont even try and please.... sorry my bad english Edited May 20, 2011 by monoscout999
Recommended Posts