Search the Community
Showing results for tags 'pixelsearch target'.
-
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!
- 19 replies
-
- pixelchecksum
- pixelsearch
-
(and 3 more)
Tagged with:
-
I am having to manually adjust the coordinates used for a PixelSearch by experimentation and have been wondering if there is some way I can display a rectangle round the area I am searching so I can speed up my manual process which I have to do if the app window is moved for any reason. My most recent reason for the move was getting a new bigger screen. I have done some searching but not found anything suitable that would only be active when I have set the TestCmd variable to 1 to indicate I am testing the Cmd segment of my script which is an automation of a game to do some resource farming. Hope someone can help me.