Jump to content

coordinate color variable dont work if it is set as variable!


Recommended Posts

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?

Edited by Daka
Link to post
Share on other sites

Maybe you should use $metaColor1 instead of $color in the PixelSearch?

If that was a typo, then try it without the quotes, because it's a number not a string.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to post
Share on other sites

I was hoping for typo, but it is not. Next code calls function:

Local $metaColor1 = 0xFF455E
   ;check if meta therapy button is availible, visible?
   If ControlCommand("[CLASS:TFormResearchGR]", "", "[CLASS:"& $btn_meta_class &"; INSTANCE:"& $btn_meta_instance &"]", "IsVisible", "") Then
      dump("$btn_metaVisible is visible"&@LF)
      $btn_metaVisible = True
      ;if meta therapy button visable, then check if meta therapy button is green and red if good connection is with headphone
      $image_path = "images\meta-therapy-green-red.bmp"
      $text = "meta therapy button not green"
      ;dump("this is text"& $text & @LF)
      $buttonActivated1 = ifButtonActivated("[CLASS:TFormResearchGR]", $btn_meta_class, $btn_meta_instance, $metaColor1, False, True, $image_path, $text)
      dump("Activated meta button: " & $buttonActivated1)

And in that function, I call: PixelSearch and if I set the sting in this function like:
$metaColor1 = 0xFF455E and set that then it works, but if I set it before when calling function it doens not wont to work. This is weird. And if I Consolewrite it, string (number) is there :(

Func ifButtonActivated($window, $button, $instance, $metaButtonColor, $click = True, $msgBoxShow = True, $image_path = False, $text = False, $litoPhyto = False)
   ConsoleWrite(@LF & "function ifButtonActivated: " & @LF)
   ConsoleWrite("$window:" & $window &" $button: "& $button &" $instance: "& $instance &" $color: "& $metaButtonColor &@LF)
   ConsoleWrite('$image_path: '& $image_path & @LF)
   Local $buttonActivated = False
   Local $buttonCanceled = False
   Local $buttonNotActivated = False
   ;because even if you bioconnector is inbetween time connected the red button will not appear
   ;so we need to loop again
   Local $litoPhytoActivated = False
   ConsoleWrite($window & @LF)
   ConsoleWrite($button & @LF)
   ConsoleWrite($instance & @LF)

   ;if button exists, research button dont exists
   Do
      If ControlCommand($window, "", "[CLASS:"& $button &"; INSTANCE:"& $instance &"]", "IsEnabled", "") Then
    ConsoleWrite($window & "[CLASS:"& $button &"; INSTANCE:"& $instance &"]IsEnabled" & @LF)
         $aPos = ControlGetPos($window, "", "[CLASS:"& $button &"; INSTANCE:"& $instance &"]")
     ConsoleWrite("$aPos[2]" & $aPos[2] & @LF)
     ConsoleWrite("$aPos[3]" & $aPos[3] & @LF)
         $sizeX = $aPos[0] + $aPos[2] + 72
         $sizeY = $aPos[1] + $aPos[3]
     $posX = $aPos[0] + 72
     $posY = $aPos[1]


         ConsoleWrite("$posX:" & $posX & "$posY:" & $posY & "$sizeX" & $sizeX & "$sizeY:" & $sizeY & "$color" & $metaButtonColor &@LF)

         ; Find a pure red pixel in the range 0,0-20,300
     ConsoleWrite(@LF & $posX & ":"& $posY & ":"& $sizeX & ":" & $sizeY & ":" & $metaButtonColor&@LF)

     ConsoleWrite($metaButtonColor& @LF)
     ConsoleWrite(Int($metaButtonColor)& @LF)
         ;Local $aCoord = PixelSearch($posX, $posY, $sizeX, $sizeY, $color)
     $metaColor1 = 0xFF455E
     ConsoleWrite($metaColor1& @LF)
     ConsoleWrite(Int($metaColor1)& @LF)
     Local $aCoord = PixelSearch($posX, $posY, $sizeX, $sizeY, $metaButtonColor)

 

Link to post
Share on other sites

This is very weird, if I pass it to function the number is there, but Pixelcoordinate dont want to accept it!

How can I see what really get the pixelcoord? Because if I print out the string it is there!

Link to post
Share on other sites

I did also like set direct to function the string:
 

$buttonActivated1 = ifButtonActivated("[CLASS:TFormResearchGR]", $btn_meta_class, $btn_meta_instance, 0xFF455E, False, True, $image_path, $text)

or

$buttonActivated1 = ifButtonActivated("[CLASS:TFormResearchGR]", $btn_meta_class, $btn_meta_instance, Int(0xFF455E), False, True, $image_path, $text)

I find it very weird :(

Link to post
Share on other sites

if I set it as Global then it works perfect, but hen I dont pass it to function.

But I can't let go how can it be that passing it to function gives different results, this is not possible!

Link to post
Share on other sites
  • Developers

Understand you like to understand why, but it would help when you post some sort of script that is runable and demonstrating the issue.

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.
  :)

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Dave1
      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!
    • By AnRios
      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  
    • By plankton
      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","")  
       
    • By plankton
      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
       
    • By Borges
      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
       
×
×
  • Create New...