Jump to content

Search the Community

Showing results for tags 'pixelsearch'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

  1. Hello everyone, I have several signals on the screen that need to be monitored while a program is running. These signals are scattered around an image which is maximized on 4 equal resolution screens - the AutoIT Window Info does not recognize any objects on the program meaning that I'm left with the PixelSearch() and PixelCheckSum() functions to monitor the signals: The signals are as small as a 5x5 pixel area and their coordinates are known. I've been digging around for a while now in this forum about the PixelSearch() and PixelCheckSum() and found some interesting and useful ideas for the use of them. I also came across some other UDF functions like MultiMon(), FastFind(), TtColXY() and the ImageSearch2015 scripts that might be useful for the final output. I don't know if hovering the mouse by using TtColXY() and output its ToolTip() information onto the log file will be faster than using PixelSearch() and/or PixelCheckSum() in a loop for all signals' coordinates. The colours of the signals are below: red - 0x00FF00 (opaque red) green - 0x00FF00 (opaque green) yellow - 0xFFFF00 (opaque yellow) black - 0x000000 (opaque black, default colour) EDIT: The desired output is to monitor and record/log the changes and status of each inside a .txt file or a .csv with the below format: Local Machine Time Signal, Change, delta-t 14:32:07 Signal1 Green - Yellow DELTA-t1 14:34:02 Signal1 Yellow - Red DELTA-t1 14:35:14 Signal2 Yellow - Red DELTA-t2 ... Below is the code I came up with. #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <misc.au3> #include <Date.au3> #include <Array.au3> #include <File.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> #include <WinAPIHObj.au3> Global $program_name, $program_open, $Wname, $tCurrent Global $button_xy[2] = [150, 175] Global $iniColour, $ColourCheck, $NewCheck Global $Red, $Green, $Blue, $Nil Global $sFilePath = @ScriptDir & "\Signals_status.txt" Global $SignalID[10] = ["Signal_1", "Signal_2", "Signal_3", "Signal_4", "Signal_5", "Signal_6", "Signal_7", "Signal_8", "Signal_9", "Signal_10"] $program_name = "Signals.exe" $Wname = "Training Task 3" $program_open = ShellExecute($program_name, @ScriptDir) WinWait($Wname) $iniColour = "0x" & Hex(PixelGetColor($button_xy[0], $button_xy[1]), 6) ;~ $iniChecksum = "0x" & Hex(PixelChecksum($button_xy[0], $button_xy[0] - 5, $button_xy[1], $button_xy[1] + 5), 6) $ColourCheck = "0x" & Hex(PixelChecksum($button_xy[0], $button_xy[0] - 5, $button_xy[1], $button_xy[1] + 5, 1, $Wname), 6) ConsoleWrite(_ColourID($iniColour) & " // " & _ColourID($ColourCheck) & @CRLF) ;~ $ColourCheck = "0x " & Hex(PixelGetColor($button_xy[0], $button_xy[1]), 6) $iniColour = $ColourCheck ;$iniChecksum = $currentCheck Do ;~ While 1 _WindowOnTop() _Close_Notepad() $NewCheck = "0x" & Hex(PixelChecksum($button_xy[0], $button_xy[0] - 5, $button_xy[1], $button_xy[1] + 5, 1, $Wname), 6) $tCurrent = _NowCalc() $LogFile = FileOpen($sFilePath, 2) FileWriteLine($LogFile, "Local Machine Time " & "Signal, " & "Change, " & "delta-t") ;~ $ColourCheck = "0x" & Hex(PixelChecksum($button_xy[0], $button_xy[0] - 5, $button_xy[1], $button_xy[1] + 5, 1, $Wname), 6) If $ColourCheck <> $NewCheck Then ;If there's a colour change from the current colour $ColourCheck = $NewCheck Local $tChange, $NewCheckID, $ColourCheckID, $sLogMsg $tChange = _NowCalc() ConsoleWrite("Colour changed!" & @CRLF) $ColourCheckID = _ColourID($ColourCheck) $NewCheckID = _ColourID($NewCheck) $iTimeDiffh = _DateDiff('h', $tChange, $tCurrent) ; time difference in hours $iTimeDiffm = _DateDiff('n', $tChange, $tCurrent) ; time difference in minutes $iTimeDiffs = _DateDiff('s', $tChange, $tCurrent) ; time difference in seconds $durationCheckSum = $iTimeDiffh & ":" & $iTimeDiffm & ":" & $iTimeDiffs ; Timestamp of the signal until PixelCheckSum $sLogMsg = " " & $SignalID[0] & " " & $ColourCheckID & " - " & $NewCheckID & " " & $durationCheckSum _FileWriteLog($LogFile, $sLogMsg) ElseIf $ColourCheck = $NewCheck Then Local $Colour_check = _ColourID("0x" & Hex(PixelChecksum($button_xy[0], $button_xy[0] - 5, $button_xy[1], $button_xy[1] + 5, 1, $Wname), 6)) ConsoleWrite($tCurrent & " " & $Colour_check & @CRLF) EndIf FileClose($sFilePath) Until Not ProcessExists($program_name) And Not WinExists($Wname) _IsProgramOpen() Func _Close_Notepad() $notepad_open = ProcessExists("notepad.exe") ? ProcessClose("notepad.exe") : ProcessClose("notepad.exe") $notepad_open = WinActive("[CLASS:Notepad]") ? WinClose("[CLASS:Notepad]") : ProcessClose("notepad.exe") EndFunc ;==>_Close_Notepad Func _ColourID($sColour) $Red = Int("0x" & StringRegExpReplace($sColour, "(..)(..)(..)(..)", "\2")) $Green = Int("0x" & StringRegExpReplace($sColour, "(..)(..)(..)(..)", "\3")) $Blue = Int("0x" & StringRegExpReplace($sColour, "(..)(..)(..)(..)", "\4")) If $Green > $Blue And $Red > $Blue And $Green >= 0xB0 And $Red >= 0xB0 Then $sCol = "Yellow" ElseIf $Blue > 0xE0 And $Green > 0xE0 And $Red > 0xE0 Then $sCol = "White" ElseIf $Blue > 0x50 And $Blue = $Green And $Blue = $Red Then $sCol = "Grey" ElseIf $Red > $Green And $Red > $Blue And $Red > 0x70 Then $sCol = "Red" ElseIf $Green > $Red And $Green >= $Blue And $Green > 0x70 Then $sCol = "Green" ElseIf $Blue > $Red And $Blue > $Green And $Blue > 0x70 Then $sCol = "Blue" Else $sCol = "Nil" EndIf Return $sCol EndFunc ;==>_ColourID Func _WindowOnTop() WinActivate($Wname) WinSetOnTop($Wname, "", $WINDOWS_ONTOP) Opt("MouseCoordMode", 0) EndFunc ;==>_WindowOnTop Func _IsProgramOpen() If Not ProcessExists($program_name) And Not WinExists($Wname) Then Break(1) EndIf EndFunc ;==>_IsProgramOpen When the program is running, the window opens in the centre of the screen however, the PixelChecksum function is not looking at the correct area. In addition: 1 - I'm not sure about how to put the message into the log file. 2 - I tested this script but it is not recording the message into the log file. 3 - Is there other way to calculate the duration in these lines? $iTimeDiffh = _DateDiff('h', $tChange, $tCurrent) ; time difference in hours $iTimeDiffm = _DateDiff('n', $tChange, $tCurrent) ; time difference in minutes $iTimeDiffs = _DateDiff('s', $tChange, $tCurrent) ; time difference in seconds $durationCheckSum = $iTimeDiffh & ":" & $iTimeDiffm & ":" & $iTimeDiffs ; Timestamp of the signal until PixelCheckSum $sLogMsg = " " & $SignalID[0] & " " & $ColourCheckID & " - " & $NewCheckID & " " & $durationCheckSum _FileWriteLog($LogFile, $sLogMsg) Thanks in advance!
  2. Greetings friends! I have been searching the help file and Google, with no success, to find a way to validate images from a folder and mark them somehow in a spreadsheet. My context is: I made a code with the help of the community that captures images from SAP and saves them in a folder. Now I'd like to identify which ones are black, if it's even possible. I read about PixelSearch, but did not get it to work. If someone could point me in the right direction, I'd appreciate it. The code I'm using: #include <File.au3> #include <ScreenCapture.au3> $x = InputBox("Title", "Amount of Images To Capture", "", "", 320, 150) If @error Then Exit $x = Number($x) $y = InputBox("Title", "Batch Name", "", "", 320, 150) If @error Then Exit $y = String($y) HotKeySet("{HOME}", "printscreen") Func printscreen() $FilePath =("C:\Fiscalizacao\Fotos"&"/") $FileName = $y & " - " $FileList = _FileListToArray($FilePath, $FileName & '*.jpg', 1) If Not IsArray($FileList) Then $FileName&= '1.jpg' Else $FileName &= $FileList[0] + 1 & '.jpg' EndIf _ScreenCapture_Capture($FilePath & "\" & $FileName, 354, 196, 673, 436) EndFunc HotKeySet("{BS}", "Terminate") Func Terminate() Exit 0 EndFunc For $i = 1 to $x Opt("WinTitleMatchMode",2) If NOT WinExists("Relatorio") Then MsgBox(0, "Atenção!", "Relatório do MOM deve estar aberto!") Call("Terminate") EndIf Opt("WinTitleMatchMode",2) WinActivate("Relatorio") Sleep (250) Opt("WinTitleMatchMode",2) SendKeepActive("Relatorio") Send("{ENTER}") Sleep (1000) Send("{HOME}") Sleep (200) Opt("WinTitleMatchMode",2) WinActivate("Relatorio") Send("{DOWN}") Next
  3. While IsArray(PixelSearch(100, 100, 300, 300, 0xffffff))     Send("{ESC}")     Sleep(1000) WEnd  MsgBox(0,"Loop exited","") Hi, above is my function that will execute ESC button when white color is present in specific area which is color 0xffffff. But how do I do the opposite like when white color is not present in that specific area? Like this below code which gives me error While IsArray(PixelSearch(100, 100, 300, 300, <>0xffffff))     Send("{ESC}")     Sleep(1000) WEnd  MsgBox(0,"Loop exited","")
  4. Hi I want it to search for a specific color in certain area then excute the loop which presses ESC button and stop the loop when the color no longer present in that specific area. Here is the example of my code. But it doesnt stop when color is disappeared. Pixelsearch(511, 455, 678, 501, 0xFFFFFF) If Not @Error Then While 1 Sleep(1000) Send("{ESC}") Pixelsearch(511, 455, 678, 501, 0xFFFFFF) If @Error Then Exitloop
  5. Sorry if I posted in wrong section but... how can I do something like that? If PixelSearch(660, 30, 670, 38, 0x242424, 0 , 1) <> @error Then Send("{F3}") Sleep(200) ElseIf PixelSearch(800, 30, 810, 38, 0x242424, 0 , 1) <> @error Then Send("{F4}") Sleep(200) EndIf
  6. I find it very weird: if I run like this: Local $aCoord = PixelSearch($posX, $posY, $sizeX, $sizeY, '0xFF455E') works fine! If I run like this: Local $metaColor1 = '0xFF455E' or like this Local $metaColor1 = "0xFF455E" or Local $metaColor1 = "'0xFF455E'" Local $aCoord = PixelSearch($posX, $posY, $sizeX, $sizeY, $color) it doesn't want to work! So something with variable is not working and yes if I print it out like this: ConsoleWrite(@LF & $posX & ":"& $posY & ":"& $sizeX & ":" & $sizeY & ":" & $color&@LF) 771:80:833:151:0xFF455E So I dont see the problem, maybe some of you people?
  7. I need help about pixel search. The problem with the script below is that PixelSearch does not continue on the coordinates where it has stopped. When the first pixelsearch finds the 1st pixel, it should move the mouse over it and new pixels would appear just like hovering over menus. Then upon hover, there would be another PixelSearch to see if the second red pixel is found. If not found, then it should resume the first PixelSearch instead of starting from left to right again. For example we are doing a pixelsearch on two straight lines with coordinates [x,y] : [0,0] [1,0] [2,0] [1,0] [1,1] [1,2] Pixelsearch finds the coordinate [1,0] matching our color. So it checks the pixel just below it which is [1,1] to see if it is color red. If not red then it should continue searching starting on coordinates [2,0] instead of going back to [0,0] Local $bflag = False Do     ToolTip("finding..",0,0,"")     Sleep(500)     $var = PixelSearch(591, 169, 1365, 740, 0x464950,50) ; look for initial pixel     If Not @error Then ;         MouseMove($var[0],$var[1],0) ;move on the button to show new selections, new pixels         sleep(1000)         ;search for the red pixel on an area above the first pixel coords which was          ;generated when mouse cursor was hovered on the first pixel found.         $redpixel = PixelSearch($var[0]-50,$var[1]-50,$var[0]+50,$var[1]+50,0xFF0048)          If Not @error Then ; Found the 2nd pixel                 ToolTip("found...",0,0,"")             $bflag = True          EndIf     EndIf Until $bflag I can pay 50USD through Paypal for a working solution. thanks
  8. Using sample code: #include <MsgBoxConstants.au3> ; Find a pure red pixel in the range 0,0-20,300 Local $aCoord = PixelSearch(0, 0, 20, 300, 0xFF0000) If Not @error Then MsgBox($MB_SYSTEMMODAL, "", "X and Y are: " & $aCoord[0] & "," & $aCoord[1]) Else MsgBox($MB_SYSTEMMODAL, "", "Pure Not Found") EndIf ; Find a pure red pixel or a red pixel within 10 shades variations of pure red $aCoord = PixelSearch(0, 0, 20, 300, 0xFF0000, 10) If Not @error Then MsgBox($MB_SYSTEMMODAL, "", "X and Y are: " & $aCoord[0] & "," & $aCoord[1]) Else MsgBox($MB_SYSTEMMODAL, "", "Variant Not Found") EndIf and the attached screenshot which has Pure Red (FF0000) in one icon in the area being searched. Would someone please check this out for me?
  9. Hello, I am new to both Programming and this forum. I have done a few tiny projects that were successful and fell in love with Autoit. So now I am trying to learn new things as I go. I have read the Help docs on my following question, I have gone thru all of that. and I am sure as soon as you see my code you will be saying OMG why did he do that, or OMG how can you forget to add this.. But when your new you take the path of least resistance to get the outcome you want. SETUP: I am trying to make a code that will open a piece of software, then open a browser (which has a handful of tabs already open) go to a web page (one of the tabs) and search an area of the web page for a specific color, if that color is found I want it to close the browser and go back and start again. If that color is not found on that page I want it to switch tabs and search that page for the color. If the color is found on that page I want it to close the browser and start again. If the color is not found on either page, I want it to open another browser and go to website and do some things I will add once i get past this obstacle. I already have it almost there my code will open my software, open the browser, do the searches, find or not find the color, the part I am having trouble with is the if and else and what happens if and what it does if it does not. So the first code I have does everything I want except if it finds the color on the first run it closes the browser, but then when it starts the process again it doesnt check for the color. its like it skips the scanning part and goes straight to the opening of the second browser and finishes the code. Run( "C:\Programs\myprogram.exe", "", @SW_SHOWDEFAULT ) Sleep(4000) MouseClick("left", 613,272) ;click in program Sleep(500) Example() Func Example() MouseClick("left", 632,456) ;click in program Sleep(500) MouseClick("left", 527,456) ;click in program Sleep(15000) Run( "C:\Programs\browser1.exe", "", @SW_SHOWMAXIMIZED ) Sleep(Random(4000,6000)) EndFunc ;==>Example MouseClick("left", 162,14) ;switch tab Sleep(Random(5000,8000)) MouseClick("left", 354,14) ;switch tab Sleep(Random(5000,8000)) $aCoord = PixelSearch(873, 485, 900, 600, 0xDD0000, 10) ;search for color If Not @error Then MouseClick("left", 1338,6) ;close browser1 Sleep(1000) Call("Example") Else MouseClick("left", 162,14) ;switch tab Sleep(1000) EndIf MouseClick("left", 162,14) ;click tab again just to be sure its loaded Sleep(4000) $aCoord = PixelSearch(1052, 308, 1120, 431, 0xFF0000, 10) ;search for this color If Not @error Then MouseClick("left", 1338,6) ;close browser1 Sleep(1000) Call("Example") Else Run( "C:\Programs\browser2.exe", "", @SW_SHOWMAXIMIZED ) Sleep(2000) EndIf MouseClick("left", 134,45) ;click on address bar Sleep(1000) Send("aspecificwebpage.com") ;input website Send("{enter}") ;hit enter Sleep(15000) MouseClick("left", 1338,6) ;close browser2 Sleep(500) MouseClick("left", 1338,6) ;close browser1 Sleep(500) MouseClick("left", 625,454) ;click in program Sleep(500) MouseClick("left", 634,271) ;click in program Sleep(500) MouseClick("left", 917,245) ;close program Sleep(500) SO it makes the first scan and is successful, if the color is found it closes as I want, but then when nit starts the code again it does not scan anything the second time. and on the other side, if the color is not found naturally everything works as it is written. I want to guess by all the weird colors in the code sniplet I have a massive amount of errors. It is like a rainbow of text up there. different from what i see in AutoIT Any help would be appreciated.
  10. I had this problem with PixelGetColor not giving me the same HEX Color as the AU3Info Tool and searched every were with no luck then had a OH DA moment LoL. The problem is that the "PixelGetColor ($mouseX[0], $mouseY[1])" is looking rite at the very tip of the mouse pointer not under it. So you have to set a -3 after the [0] and [1]. "PixelGetColor ($mouseX[0] -3, $mouseY[1] -3)" to make it search next to the pointer not on the pointer. You may have to adjust this a bit for your display but you should not have to go more then -5. -3 seems to work best for me. Example.au3 #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 141, 127, 276, 231) $Input1 = GUICtrlCreateInput("", 8, 8, 121, 21) $Label1 = GUICtrlCreateLabel("Press or Hold F1 to get Hex color at Mouse X -3, Y-3 Pos,", 8, 40, 124, 73) GUISetState(@SW_SHOW) HotKeySet("{f1}","MousePos") Func MousePos() $aPos = MouseGetPos() $PGC = PixelGetColor($aPos[0] -3, $aPos[1] -3) GUICtrlSetData($Input1, "0x" & Hex($PGC, 6)) EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
  11. how to find the location on an image color ?? Similar PixelSearch, but in a format bmp image search 0x0806EB and returns coordinates sorry I am not good at English
  12. PixelSearch in a GUI window which state's @SW_MINIMIZE. Is it possible?
  13. Hello, I've wrote a fairly straight forward script that will search an area of the screen and then left click on apart of that area should it find a certain color/pixel. I have a small issue where by within the area, multiple pixels of the same color will appear, the script will continue to click on the same pixel over and over again. Is there a way so that it will cycle through all the results and click on each one for a given time period then move onto the next, as apose to clicking on the same spot forever. I have used timers before and that shouldn't be an issue, its more the having it stop clicking, or ignoring the current pixel its clicking and then moving onto the next one (same pixel color within same area). Hopefully this makes sense. [autoit] HotKeySet("{ESC}", "END_EXIT") HotKeySet("+1", "start") While 1     Sleep(100)  WEnd func start()    while 1 $location = PixelSearch( 631, 175, 1181, 597, 0xFF0000) If IsArray ($location) = 1 Then     MouseClick ('left', $location[0], $location[1], 1, 0)  EndIf  WEnd EndFunc  func END_EXIT()  Exit  EndFunc [/autoit]
  14. Greetings, Func pixelHunter () Local $PixelHunt[2] Do $PixelHunt = PixelSearch (1, 1, 1016, 874, "0xCCE4CC", 0, 1, $sWorkOrderWin) Until $PixelHunt[0] > 0 EndFunc So when I call up this function in my app it fires back "Subscript used on non-accessible variable" Now, if I am understanding this message properly it is trying to tell me that the variable can't be seen by the function asking for it. I replaced "Do...Until" with simply a "ConsoleWrite" the $PixelHunt value and it doesn't throw that error. Any advice would be appreciated! -Reiz
  15. Sir/Ma'am, I am new to autoit so please bear with me, i need help with this please see attached file, many thanks to all. $color1 = 0xED1C24 ;red $color2 = 0xFFFFFF ;white $color3 = 0x22B14C ;green $color4 = 0x00A2E8 ;blue ;lets say (999,366,1331,566) is the yellow outer square $Scan_Area = PixelSearch(999,366,1331,566,$color1) ;how do i delete the BOX2 & BOX1 but not delete BOX3? while(1) if IsArray($Scan_Area) = ???? then Mousemove($Scan_Area[0],$Scan_Area[1],10) Mouseclick($Scan_Area[0],$Scan_Area[1],1,10) Send("{delete}") Sleep(500) Endif Wend
  16. I have a need to make the mouse push down the the left button and trace a shape that goes in all directions . If it can follow the line in a full circle I'd be set. I'm not concerned with the left mouse down, I have that figured out for later. My problem is having the cursor follow a circle in paint. It'll follow some but I think it's going toward 0,0 I'm guessing but falls off once it gets to a certain point. I've searched, I've tried several methods. This code below has been the simplest that works close but won't follow a full, or half circle. It just falls off. More detail that you need but if you've ever seen contour lines on a map, that's what I'm ultimately wanting to follow. I'll be doing it on my own images that I create by scanning the water with sonar and making lake maps. I want to put my image on google earth and turn the contour lines into paths so they have latitude longitude data. Tracing them manually is very time consuming and accuracy suffers. Thank you for any time you spend on this. It would be very helpful. HotKeySet("{ESC}", "Terminate") Const $color = 0x000000 Local $start = MouseGetPos() While 1 $pos = MouseGetPos() If $pos = $start Then ContinueLoop $pix = PixelSearch($pos[0] - 5, $pos[1] - 5, $pos[0] + 5, $pos[1] + 5, $color, 5) If @error = 1 Then ContinueLoop $start = $pos MouseMove($pix[0], $pix[1]) Wend Func Terminate() Exit EndFunc
  17. hello i'm here again i know im quite annoying because i ask nonsense questions >.< i just wanted to improve my automated autoclicker yahoomail I wanted to check if it is match pink and white color using AND operator && but i cant make it to work im really newbie in programming ,i wanted to learn more, i hope you help me again Func CheckIfMatch() $pink = PixelSearch(0, 0, @DesktopHeight, @DesktopWidth, 0x2f0326) && If PixelGetColor ( 1002 , 236 ) = 0xFFFFFF && If isArray($pink) then Send("{F5}") MouseClick("primary", $pink[0] , $pink[1], 0, 0) Else MouseClick("primary", $pink[0] , $pink[1], 0, 0) EndIf EndFunc
  18. Here's the goal: Create a handle to a bitmap object using _WinApi_PrintWindow (this is done and working properly, I can take a screenshot of the window even when it's hidden or offscreen, does not work minimized)Be able to search for a pixel color in memory on the handle. I can get it to work if I create a Bitmap from an HBITMAP (_GDIPlus_BitmapCreateFromHBITMAP) and then go through each pixel and check it using _GDIPlus_BitmapGetPixel but it's too slow. I've tried doing the _WinApi_GetPIxel using an $hDC but it's much slower than GDI+ (GD+ takes about 20seconds to search for almost 500,000 pixels, GetPixel takes almost 60seconds)I found the FastFind library but, honestly, it's sloppy and I'm wanting to search a defined area, not set the starting position and then search the rest of the window. I also found a few examples on the forums but I could not get them to work. Here's the CaptureWindow function. I'm only wanting to capture the client area (Not the border around the client, hence the -16 for the width and the -38 for the height, gets rid of the title bar and the resize bars on the sides. Also I'm wanting to keep the coordinates relative to the window, so if you only want to capture the screen from 480, 200 to 680, 400, then the rest of the area is black on purpose) #include-once Func CaptureWindow(Const $iLeft = 0, Const $iTop = 0, Const $iWidth = -1, Const $iHeight = -1, Const $hWindow = WinGetHandle("[Active]")) Local $rect_window = WinGetPos($hWindow) Local $hDC = _WinAPI_GetWindowDC($hWindow) Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $rect_window[2] - 16, $rect_window[3] - 38) Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap) Local $hSrcDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $rect_window[2] - 16, $rect_window[3] - 38) Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBmp) _WinAPI_PrintWindow($hWindow, $hSrcDC, True) If ($iWidth > 0 and $iHeight > 0) Then _WinAPI_BitBlt($hDestDC, $iLeft, $iTop, $iWidth, $iHeight, $hSrcDC, $iLeft, $iTop, $MERGECOPY) Else _WinAPI_BitBlt($hDestDC, $iLeft, $iTop, $rect_window[2] - 16 - $iLeft, $rect_window[3] - 38 - $iTop, $hSrcDC, $iLeft, $iTop, $MERGECOPY) EndIf _WinAPI_SelectObject($hDestDC, $hDestSv) _WinAPI_SelectObject($hSrcDC, $hSrcSv) _WinAPI_ReleaseDC($hWindow, $hDC) _WinAPI_DeleteDC($hDestDC) _WinAPI_DeleteDC($hSrcDC) _WinAPI_DeleteObject($hBmp) Return $hBitmap EndFunc ;==>CaptureWindowAnd the first attempt for PixelSearch, using GDI+ (Fastest) Func PixelSearchInhBitmap(Const ByRef $hHBmp, Const ByRef $color, Const $tolerance = 10, Const $iLeft = 0, Const $iTop = 0, $iWidth = -1, $iHeight = -1, Const $iStep = 1) Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) Local $rbg_color = _ColorGetRGB("0x" & Hex($color, 6)) Local $found_color = False Local $abscoord_color[2] = [0, 0] Local $red_low = 0 Local $green_low = 0 Local $blue_low = 0 Local $red_high = 0 Local $green_high = 0 Local $blue_high = 0 $red_low = ($tolerance > $rbg_color[0] ? 0 : $rbg_color[0] - $tolerance) $green_low = ($tolerance > $rbg_color[1] ? 0 : $rbg_color[1] - $tolerance) $blue_low = ($tolerance > $rbg_color[2] ? 0 : $rbg_color[2] - $tolerance) $red_high = ($tolerance > 255 - $rbg_color[0] ? 255 : $rbg_color[0] + $tolerance) $green_high = ($tolerance > 255 - $rbg_color[1] ? 255 : $rbg_color[1] + $tolerance) $blue_high = ($tolerance > 255 - $rbg_color[2] ? 255 : $rbg_color[2] + $tolerance) If ($iWidth = -1) Then $iWidth = _GDIPlus_ImageGetWidth($hBitmap) If ($iHeight = -1) Then $iHeight = _GDIPlus_ImageGetHeight($hBitmap) Local $start_time = TimerInit() For $iY = $iTop To $iHeight Step $iStep For $iX = $iLeft To $iWidth Step $iStep Local $get_pixel = _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY) If (@Error) Then ContinueLoop Local $pixel_color = _ColorGetRGB("0x" & Hex($get_pixel, 6)) If (@Error) Then ContinueLoop If (($pixel_color[0] >= $red_low and $pixel_color[0] <= $red_high) and ($pixel_color[1] >= $green_low and $pixel_color[1] <= $green_high) and ($pixel_color[2] >= $blue_low and $pixel_color[2] <= $blue_high)) Then $found_color = True $abscoord_color[0] = $iX $abscoord_color[1] = $iY ExitLoop 2 EndIf Next Next MsgBox("", "", TimerDiff($start_time) / 1000) _GDIPlus_BitmapDispose($hBitmap) If ($found_color) Then Return $abscoord_color Else Return SetError(-1, 0, 0) EndIf EndFuncSecond attempt using _WInApi_GetPixel (Note. I replaced the Autoit function with my own where I replaced the string "gdi32.dll" with a handle to the opened DLL. In the hopes it would improve time. The time difference was not noticable) Global $HWND_DLL_GDI32 = DLLopen("gdi32.dll") Func PixelSearchInhDC(Const ByRef $color, Const $tolerance = 10, Const $iLeft = 0, Const $iTop = 0, $iWidth = -1, $iHeight = -1, Const $iStep = 1, Const $hWnd_window = WinGetHandle("[Active]")) Local $hDC = _WinAPI_GetWindowDC($hWnd_window) Local $rbg_color = _ColorGetRGB("0x" & Hex($color, 6)) Local $found_color = False Local $abscoord_color[2] = [0, 0] Local $start_time, $end_time Local $red_low = 0 Local $green_low = 0 Local $blue_low = 0 Local $red_high = 0 Local $green_high = 0 Local $blue_high = 0 If (Not $hDC) Then Return SetError(1, 0, 0) EndIf If ($iWidth = -1 or $iHeight = -1) Then Local $rect_window = WinGetPos($hWnd_window) If ($iWidth = -1) Then $iWidth = $rect_window[2] - $iLeft If ($iHeight = -1) Then $iHeight = $rect_window[3] - $iTop EndIf $red_low = ($tolerance > $rbg_color[0] ? 0 : $rbg_color[0] - $tolerance) $green_low = ($tolerance > $rbg_color[1] ? 0 : $rbg_color[1] - $tolerance) $blue_low = ($tolerance > $rbg_color[2] ? 0 : $rbg_color[2] - $tolerance) $red_high = ($tolerance > 255 - $rbg_color[0] ? 255 : $rbg_color[0] + $tolerance) $green_high = ($tolerance > 255 - $rbg_color[1] ? 255 : $rbg_color[1] + $tolerance) $blue_high = ($tolerance > 255 - $rbg_color[2] ? 255 : $rbg_color[2] + $tolerance) $start_time = TimerInit() For $iY = $iTop To $iHeight Step $iStep For $iX = $iLeft To $iWidth Step $iStep Local $get_pixel = __WinAPI_GetPixel($hDC, $iX, $iY) If (@Error) Then ContinueLoop Local $pixel_color = _ColorGetRGB("0x" & Hex($get_pixel, 6)) If (@Error) Then ContinueLoop If (($pixel_color[0] >= $red_low and $pixel_color[0] <= $red_high) and ($pixel_color[1] >= $green_low and $pixel_color[1] <= $green_high) and ($pixel_color[2] >= $blue_low and $pixel_color[2] <= $blue_high)) Then $found_color = True $abscoord_color[0] = $iX $abscoord_color[1] = $iY ExitLoop 2 EndIf Next Next MsgBox("", "", TimerDiff($start_time) / 1000 & "s") If ($found_color) Then Return $abscoord_color Else Return SetError(1, 0, 0) EndIf EndFunc Func __WinAPI_GetPixel($hDC, $iX, $iY) Local $aRet = DllCall($HWND_DLL_GDI32, 'dword', 'GetPixel', 'handle', $hDC, 'int', $iX, 'int', $iY) If @error Or ($aRet[0] = 4294967295) Then Return SetError(@error, @extended, -1) ; If $aRet[0] = 4294967295 Then Return SetError(1000, 0, -1) Return __RGB($aRet[0]) EndFunc ;==>__WinAPI_GetPixel
  19. i have similar problem pixelsearch. but i found an ahk script solution from google. can anyone help me convert ahk to autoit script? im really new to this heres ahk script MainLoop() { Loop { PixelSearch, X, Y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x00FF00, 0, fast if(ErrorLevel=0) { MouseClick, left, %X%, %Y% sleep, 300 RefinedLoop(x, y) } RefinedLoop(pX, pY) { Loop { pX := X + 50 pY := y + 50 dX := X - 50 dY := Y - 50 PixelSearch, X, Y, %pX%, %pY%, %dX%, %dY%, 0x00FF00, 0, fast if(ErrorLevel=0) { MouseClick, left, %X%, %Y% sleep, 300 } Else if (ErrorLevel <> 0) i++ If (i > 10) MainLoop() } } i tried to convert to autoit but gives me bunch of error Func MainLoop() While 1 $green = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0x00ff00) If isArray($green) then MouseClick("primary", $green[0], $green[1] , 1, 0) RefinedLoop(pX, pY) } RefinedLoop(pX, pY) { while 1 pX = X + 50 pY = y + 50 dX = X - 50 dY = Y - 50 $green = PixelSearch($pX, $pY, $dX, $dY 0x00ff00) If isArray($green) then MouseClick("primary", $green[0], $green[1] , 1, 0) Else if @ErrorLevel <> 0 i++ If (i > 10)
  20. sometimes my script just hovering mouseMove to the target continuously.. and not left clicking it ..whats the problem? Func Start() While 1 $pxs2 = PixelSearch(70, 102, 1181, 654, 0x6b2900) If isArray($pxs2) then MouseMove($pxs2[0]+40,$pxs2[1]+40, 0) sleep(100) MouseClick("Left") Else $pxs3 = PixelSearch(70, 102, 1181, 654, 0x6b29a4) If isArray($pxs3) then MouseMove($pxs3[0]+40,$pxs3[1]+40, 0) sleep(100) MouseClick("Left") Else $pink = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0x8a0859) If isArray($pink) then MouseMove($pink[0],$pink[1], 0) sleep(100) MouseClick("Left") Else $pink2 = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0x8c085a) If isArray($pink2) then MouseMove($pink2[0],$pink2[1], 0) sleep(100) MouseClick("Left") Else $pink3 = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0x880852) If isArray($pink3) then MouseMove($pink3[0],$pink3[1], 0) sleep(100) MouseClick("Left") Else $green = PixelSearch(70, 102, 1181, 654, 0x00FF00) If isArray($green) then Send("{F3}") MouseMove($green[0]+25,$green[1]+25, 0) sleep(100) MouseClick("Left") Else Send("{F9}") Sleep(700) EndIf EndIf EndIf EndIf EndIf EndIf WEnd EndFunc
  21. my script is working fine but it mostly clicks only in the sides and corner of green square (which is the first pixels it detects i guess) any idea how can I click the middle area inside of pixelsearch? heres what i done but it wont work $greenbox = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0x00FF00) If isArray($greenbox) then newX := greenbox[0] + 25 newY := greenbox[1] + 25 MouseMove($newX[0],$newY[1], 0) MouseClick("Left")
  22. I want to do several Pixelsearches on my Screen to find out if i can find the Chrome Browser ^^ Instead of one big search on the screen i run $pixesearch1,$pixesearch2,$pixesearch3 etc. on a sliced up Screen. I have done something similar before.. But i wanted to ask if i should use Switch or Select? Do they only run ONE of their cases? or run as many cases that are True?
  23. How can I search for a certain color in a background or masked window by other windows( no minimized ), and get the color's relative window's coordinates ?? Is it possible ? I appreciate any help....
  24. Let’s say I want to do pixelsearch within coordinates 0, 0, 100, 100, but I would like to ignore pixels in area 10,10,20,20. Is it possible to achieve?
  25. While i am waiting for Better Solutions for Finding Multiple @error Cases and React according to them, i am hoping that some1 could explain me what my problem in this (time consuming) function is.. The Idea is that i check for @Errors from the 3 PixelSearch i am doing, and give Message according to it. I am changing Colors In Paint for Every Loop To Test If the Color Searches Are Correct. All Cases are Working Fine, and the Right MsgBoxes are Triggered, Except the Case where all 3 Colors are Missing: HotKeySet("{ESC}", "End") Global $pixelSearchError1 = @error Global $pixelSearchError2 = @error Global $pixelSearchError3 = @error While 1 Sleep(10) $pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10) ;Blue $pixelSearchError1 = @error $pixelsearch2 = PixelSearch(250,310,400,512,0xfa0000,10) ;Red $pixelSearchError2 = @error $pixelsearch3 = PixelSearch(500,300,600,512,0x00ff00,10) ;Green $pixelSearchError3 = @error Call("_errorcheck") WEnd Func _errorcheck() Sleep(100) Select ;Check for Blue Color, Then Proceed. Case Not $pixelSearchError1 ;Found Blue MsgBox(0,"Message","Blue Pixel Found!") Select ;Blue Found. Now check for Red Case Not $pixelSearchError2 ;Found Blue and Red MsgBox(0,"Message","Blue and Red Pixel Found!") Select ;Blue and Red found. Now check for Green Case Not $pixelSearchError3 ;Found Blue, Red and Green MsgBox(0,"Message","Blue,Red and Green Pixel Found!") Case $pixelSearchError3 ;Blue, Red But not Green MsgBox(0,"Message","Found Blue, Red But Not Green") EndSelect Case $pixelSearchError2 ;Blue Found, But Not Red MsgBox(0,"Message","Blue Found, But Not Red") Select ;Blue and Red found. Now check for Green Case Not $pixelSearchError3 ;Found Blue, Green But not Red MsgBox(0,"Message","Found Blue, Green But Not Red") Case $pixelSearchError3 ;Blue, But not Red or Green MsgBox(0,"Message","Could only Find Blue") EndSelect EndSelect Case $pixelSearchError1 ;Blue Not Found MsgBox(0,"Message","Blue Pixel Not Found") Select ;Blue Not Found. Now check for Red Case Not $pixelSearchError2 ;Found Red, But not Blue MsgBox(0,"Message","Found Red, But not Blue") Select ;Found Red, But not Blue Now check for Green Case Not $pixelSearchError3 ;Red and Green, but not Blue MsgBox(0,"Message","Red,Green But not Blue") Case $pixelSearchError3 ;Red, But not Blue or Green MsgBox(0,"Message","Could only Find Red") EndSelect Case $pixelSearchError2 ;Could not find Blue or Red MsgBox(0,"Message","Could not Find Blue and Red") Select ;Blue and Red Not found. Now check for Green Case Not $pixelsearch3 ;Only found Green MsgBox(0,"Message","Only found Green") Case $pixelSearchError3 ;Did not Find Blue,Red or Green MsgBox(0,"Message","No Color was found") EndSelect EndSelect EndSelect Sleep(10) EndFunc I Made a Picture that should make it far easier to see where one Select Case Starts and Ends Check the Link Below. http://imageshack.us/f/9/selectcasegreenerror.gif/ I can't see why the Last Case is not working.. When Blue,Red AND Green are Missing i still get the "Only found Green" Please Help Also, Building the Cases Like this takes up allot of Time and Space, so if you have a Easier way please Tell Like: If Not @error 1 And @error 2 And @error 3 Then But i don't think that Works. I probably want to run 5 PixelSearches and that would mean 5 Select an 32 Cases !!!1!!11 So it would be Great if there was another way of doing this If not, Please do still tell what the problem of my Function is
×
×
  • Create New...