Jump to content


Photo

Finding the source of ErrorLevel = 2 in PixelSearch


  • Please log in to reply
14 replies to this topic

#1 dra

dra
  • Members
  • 100 posts

Posted 02 August 2012 - 12:04 AM

The function below is part of a 250 line script:
ConfirmDesiredPixelAtLocation(Flag, WindowTitle, X, Y, DesiredColor, LocationComment, LoopTime)
{
	;transform the coordinates from 1680 x 1050 resolution to current screen resolution
	X := X//(1680/A_ScreenWidth)
	Y := Y//(1050/A_ScreenHeight)
	Xmin := X-2
	Xmax := X+2 
	Ymin := Y-2 
	Ymax := Y+2
	EndTime := A_TickCount+LoopTime+1
	
	ClipBoard =
	ClipBoard = %ClipBoard% X = %X% `r`n
	ClipBoard = %ClipBoard% Y = %Y% `r`n	
	ClipBoard = %ClipBoard% Xmin = %Xmin% `r`n
	ClipBoard = %ClipBoard% Xmax = %Xmax% `r`n
	ClipBoard = %ClipBoard% Ymin = %Ymin% `r`n
	ClipBoard = %ClipBoard% Ymax = %Ymax% `r`n
	ClipBoard = %ClipBoard% LoopTime = %LoopTime% `r`n
	ClipBoard = %ClipBoard% DesiredColor = %DesiredColor% `r`n
	ClipBoard = %ClipBoard% EndTime = %Endtime% `r`n
	ClipBoard = %ClipBoard% `r`n
	
	While A_TickCount<EndTime 
	{
		PixelSearch, OutputVarX, OutputVarY, Xmin, Ymin, Xmax, Ymax, DesiredColor, 5, Fast
		If ErrorLevel=0
		{
			Return 0
		}
		Sleep 10
	}
	If (Flag=1 and ErrorLevel=1)
	{
		Return 1
	}
	Else If (Flag=0 and ErrorLevel=1)
	{
		WinGetActiveTitle, CurrentTitle
		MouseMove, X, Y
		;ClipBoard =
		ClipBoard = %ClipBoard%  Problem in ConfirmDesiredPixelAtLocation - Unable to find pixel at %LocationComment%`r`n
		ClipBoard = %ClipBoard% `r`n
		ClipBoard = %ClipBoard% Trying to find %LocationComment% on %WindowTitle%`r`n
		ClipBoard = %ClipBoard% The mouse is currently positioned on the target`r`n
		ClipBoard = %ClipBoard% Search centered at (%X%, %y%) on %CurrentTitle%`r`n
		ClipBoard = %ClipBoard% Search grid is (%Xmin% to %Xmax%, %Ymin% to %Ymax%)`r`n
		ClipBoard = %ClipBoard% `r`n
		ClipBoard = %ClipBoard% The above result is on clipboard `r`n
		ClipBoard = %ClipBoard% Exiting script `r`n
		MsgBox, %ClipBoard%
		Exit
	}
	Else
	{
		WinGetActiveTitle, CurrentTitle
		;ClipBoard =
		ClipBoard = %ClipBoard% Problem in ConfirmDesiredPixelAtLocation - Invalid ErrorLevel or Flag while attemptng to find %LocationComment%`r`n
		ClipBoard = %ClipBoard% `r`n
		ClipBoard = %ClipBoard% ErrorLevel = |%ErrorLevel%|`r`n
		ClipBoard = %ClipBoard% Flag = |%Flag%|`r`n
		ClipBoard = %ClipBoard% CurrentTitle = |%CurrentTitle%|`r`n
		ClipBoard = %ClipBoard% WindowTitle  = |%WindowTitle%|`r`n
		ClipBoard = %ClipBoard% Valid error levels are 0 & 1.`r`n
		ClipBoard = %ClipBoard% `r`n
		ClipBoard = %ClipBoard% The above result is on clipboard `r`n
		ClipBoard = %ClipBoard% Exiting script `r`n
		MsgBox, %ClipBoard%
		Exit
	}
}
When I run it, I get the following output:

X = 20.000000
Y = 67.000000
Xmin = 18.000000
Xmax = 22.000000
Ymin = 65.000000
Ymax = 69.000000
LoopTime = 5000
DesiredColor = 0xFCAB72
EndTime = 138043047

Problem in ConfirmDesiredPixelAtLocation - Invalid ErrorLevel or Flag while attemptng to find blue chimney on Home tab

ErrorLevel = |2|
Flag = |0|
CurrentTitle = |correct window title - cant display it|
WindowTitle = |correct window title - cant display it|
Valid error levels are 0 & 1.

The above result is on clipboard
Exiting script


The description of PixelSearch in the command list states:

ErrorLevel is set to 0 if the color was found in the specified region, 1 if it was not found, or 2 if there was a problem that prevented the command from conducting the search.

I am not much of programmer and havent a clue how to determine the problem preventing this command from being executed. This is the only place PixelSearch appears in my script. There arent any other scripts loaded. There arent any parallel threads running that I am aware of. Some help would be appreciated. Thanks.

#2 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 02 August 2012 - 03:57 AM

The color parameter must be a value, therefore %% are required around a variable
PixelSearch, OutputVarX, OutputVarY, Xmin, Ymin, Xmax, Ymax, [color=#FF0000]%[/color]DesiredColor[color=#FF0000]%[/color], 5, Fast


#3 dra

dra
  • Members
  • 100 posts

Posted 02 August 2012 - 04:06 PM

Thanks for your help but neither:

PixelSearch, OutputVarX, OutputVarY, Xmin, Ymin, Xmax, Ymax, %DesiredColor%, 5, Fast
or

PixelSearch, OutputVarX, OutputVarY, %Xmin%, %Ymin%, %Xmax%, %Ymax%, %DesiredColor%, 5, Fast
fix the problem. ErrorLevel=2 is still the result.

Any other ideas? Thanks again.

#4 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 02 August 2012 - 04:34 PM

Since the documentation says that xmin ... ymax can be expressions, the %% are not required, but are not harmful.
Using %DesiredColor% is >>essential<<.

I notice that you are using "clipboard" to assemble your error message.
Did you know about the command "listvars"? It might be simpler to see the results.

I see nothing wrong with the values that have been returned that would account for the errorlevel = 2

I do not see any commands that have results that would change errorlevel.
However, I am concerned about the value of "errorlevel" being changed by accident.
1. My first suggestion is to add a surrogate variable "err" that only you can change,
assign a value as shown beloe and then and then use "err" instead of "errorlevel".

PixelSearch, OutputVarX, OutputVarY, Xmin, Ymin, Xmax, Ymax, DesiredColor, 5, Fast
err := errorlevel ;<--- add this line


The function below is part of a 250 line script:

Your function is approximately 70 lines, of 250. So, roughtly 1/4 of the total script length.

I suggest you need to set aside the script as is and focus on making the function work.
Did you ever try a simple PixelSearch with just hard-coded parameters for xmin... desiredcolor ?

#5 dra

dra
  • Members
  • 100 posts

Posted 02 August 2012 - 08:44 PM

Thanks for the tips. The simplified script with revised function is:

^#!z::
CoordMode, ToolTip, 1
CoordMode, Pixel, 1
CoordMode, Mouse, 1
ToolTip

SetTitleMatchMode, Slow
SetWinDelay, 1000
SetControlDelay, 100

IfWorkSpaceOpen:
	IsWorkSpaceOpen := ConfirmDesiredPixelAtLocation(1, WindowTitle, 333, 68, 0x707070, "X on workspace tab", 5000) 
	MsgBox IsWorkSpaceOpen = %IsWorkSpaceOpen%
	Return
	
ConfirmDesiredPixelAtLocation(Flag, WindowTitle, X, Y, DesiredColor, LocationComment, LoopTime)
{
	;transform the coordinates from 1680 x 1050 resolution to current screen resolution
	X := X//(1680/A_ScreenWidth)
	Y := Y//(1050/A_ScreenHeight)
	Xmin := X-2
	Xmax := X+2 
	Ymin := Y-2 
	Ymax := Y+2
	EndTime := A_TickCount+LoopTime+1
	
	While A_TickCount<EndTime 
	{
		PixelSearch, OutputVarX, OutputVarY, Xmin, Ymin, Xmax, Ymax, %DesiredColor%, 5, Fast
		Err := ErrorLevel
		If Err=0
		{
			Return 0
		}
		Sleep 10
	}
	If (Flag=1 and Err=1)
	{
		Return 1
	}
	Else If (Flag=0 and Err=1)
	{
		Return
	}
	Else
	{
		ListVars
		ClipBoard =
		ClipBoard = %ClipBoard%Problem in ConfirmDesiredPixelAtLocation`r`n
		ClipBoard = %ClipBoard%Exiting script`r`n
		MsgBox, %ClipBoard%
		Exit
	}
}

ListVars produces:

Local Variables for ConfirmDesiredPixelAtLocation()
--------------------------------------------------
DesiredColor[8 of 63]: 0x707070
EndTime[9 of 63]: 212191001
Err[1 of 3]: 2
Flag[1 of 3]: 1
LocationComment[18 of 63]: X on workspace tab
LoopTime[4 of 7]: 5000
OutputVarX[0 of 0]:
OutputVarY[0 of 0]:
WindowTitle[73 of 259]: Correct IE Page - cant display result
X[10 of 63]: 333.000000
Xmax[10 of 63]: 335.000000
Xmin[10 of 63]: 331.000000
Y[9 of 63]: 68.000000
Ymax[9 of 63]: 70.000000
Ymin[9 of 63]: 66.000000


Global Variables (alphabetical)
--------------------------------------------------
0[1 of 3]: 0
ErrorLevel[1 of 3]: 2
IsWorkSpaceOpen[0 of 0]:
WindowTitle[73 of 259]: Correct IE Page - cant display result

The problem still exists i.e. ErrorLevel = Err = 2. Any other ideas? Thanks again.

#6 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 02 August 2012 - 10:17 PM

These lines are not valid, because of the 2nd paramenter
CoordMode, ToolTip, 1
CoordMode, Pixel, 1
CoordMode, Mouse, 1

Per the documentation, that parameter must be either Screen or Relativehttp://www.autohotke...s/CoordMode.htm
The documentatiopn also states:
If this command is not used, all commands except those documented otherwise (e.g. WinMove and InputBox) use coordinates that are relative to the active window.

I have found this method works correctly
if 1	; screen coordinates
  coord=screen
else
  coord=relative
tooltip, %coord%
sleep, 1000

CoordMode, ToolTip, %coord%
CoordMode, Pixel, %coord%
CoordMode, Mouse, %coord%
CoordMode, Caret, %coord%
CoordMode, Menu, %coord%
tooltip

Regardless of the above statements.
Please add the following lines to the top of your script.
Gui, Add, Progress,  h100 w400 cBlue vMyProgress, 95
gui, add, edit, vmycolor gcolor
mycolor = 0x707070

guicontrol, +c%mycolor%, MyProgress
gui, show, 
return

Save & Run the script, make sure the gui is the active window and hit you hotkey ^#!z

my result is IsWorkSpaceOpen = 0 :D

#7 dra

dra
  • Members
  • 100 posts

Posted 03 August 2012 - 12:38 AM

Thanks for catching the problem with the CoordMode. I wont be doing relative coordinates so I have tried to simplify it to:

CoordMode, ToolTip, screen
CoordMode, Pixel, screen
CoordMode, Mouse, screen

I added the GUI at the top as you suggested so that it reads as follows:
^#!z::
Gui, Add, Progress,  h100 w400 cBlue vMyProgress, 95
gui, add, edit, vmycolor gcolor
mycolor = 0x707070

guicontrol, +c%mycolor%, MyProgress
gui, show, 
return

CoordMode, ToolTip, screen
CoordMode, Pixel, screen
CoordMode, Mouse, screen

SetTitleMatchMode, Slow
SetWinDelay, 1000
SetControlDelay, 100

IfWorkSpaceOpen:
	IsWorkSpaceOpen := ConfirmDesiredPixelAtLocation(1, WindowTitle, 333, 68, 0x707070, "X on workspace tab", 5000) 
	MsgBox IsWorkSpaceOpen = %IsWorkSpaceOpen%
	Return
	
ConfirmDesiredPixelAtLocation(Flag, WindowTitle, X, Y, DesiredColor, LocationComment, LoopTime)
{
	;transform the coordinates from 1680 x 1050 resolution to current screen resolution
	X := X//(1680/A_ScreenWidth)
	Y := Y//(1050/A_ScreenHeight)
	Xmin := X-2
	Xmax := X+2 
	Ymin := Y-2 
	Ymax := Y+2
	EndTime := A_TickCount+LoopTime+1
	
	While A_TickCount<EndTime 
	{
		PixelSearch, OutputVarX, OutputVarY, Xmin, Ymin, Xmax, Ymax, %DesiredColor%, 5, Fast
		Err := ErrorLevel
		If Err=0
		{
			Return 0
		}
		Sleep 10
	}
	If (Flag=1 and Err=1)
	{
		Return 1
	}
	Else If (Flag=0 and Err=1)
	{
		Return
	}
	Else
	{
		ListVars
		ClipBoard =
		ClipBoard = %ClipBoard%Problem in ConfirmDesiredPixelAtLocation`r`n
		ClipBoard = %ClipBoard%Exiting script`r`n
		MsgBox, %ClipBoard%
		Exit
	}
}

but the script wont run and I get an error msg regarding the GUI (which I know nothing about). Your help would be appreciated.

#8 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 03 August 2012 - 01:00 AM

Thanks for catching the problem with the CoordMode.
I wont be doing relative coordinates so I have tried to simplify it to:

Seems fine to me.

I added the GUI at the top as you suggested so that it reads as follows:

Technically, no you didn't. Please read the first paragraph here
The Top of the Script (the Auto-execute Section)
<!-- m -->http://www.autohotke...cripts.htm#auto<!-- m -->
It woul be a good idea to read the whole section, and even the whole page when you are learning AHk.

So let me repeat Please add the following lines to the top of your script.

but the script wont run

Didn't you notice the return command :?:
That is why I want you to move my lines to the top, above your hotkey.

...and I get an error msg regarding the GUI

My apologies, please delete the line gui, add, edit, vmycolor gcolor

#9 dra

dra
  • Members
  • 100 posts

Posted 03 August 2012 - 04:14 PM

Thanks again for helping me debug this script and learn AHK. The script now reads:

Gui, Add, Progress,  h100 w400 cBlue vMyProgress, 95
mycolor = 0x707070
guicontrol, +c%mycolor%, MyProgress
gui, show, 
return

^#!z::
CoordMode, ToolTip, screen
CoordMode, Pixel, screen
CoordMode, Mouse, screen

SetTitleMatchMode, Slow
SetWinDelay, 1000
SetControlDelay, 100

IfWorkSpaceOpen:
	IsWorkSpaceOpen := ConfirmDesiredPixelAtLocation(1, WindowTitle, 333, 68, 0x707070, "X on workspace tab", 5000) 
	MsgBox IsWorkSpaceOpen = %IsWorkSpaceOpen%
	Return
	
ConfirmDesiredPixelAtLocation(Flag, WindowTitle, X, Y, DesiredColor, LocationComment, LoopTime)
{
	;transform the coordinates from 1680 x 1050 resolution to current screen resolution
	X := X//(1680/A_ScreenWidth)
	Y := Y//(1050/A_ScreenHeight)
	Xmin := X-2
	Xmax := X+2 
	Ymin := Y-2 
	Ymax := Y+2
	EndTime := A_TickCount+LoopTime+1
	
	While A_TickCount<EndTime 
	{
		PixelSearch, OutputVarX, OutputVarY, Xmin, Ymin, Xmax, Ymax, %DesiredColor%, 5, Fast
		Err := ErrorLevel
		If Err=0
		{
			Return 0
		}
		Sleep 10
	}
	If (Flag=1 and Err=1)
	{
		Return 1
	}
	Else If (Flag=0 and Err=1)
	{
		Return
	}
	Else
	{
		ListVars
		ClipBoard =
		ClipBoard = %ClipBoard%Problem in ConfirmDesiredPixelAtLocation`r`n
		ClipBoard = %ClipBoard%Exiting script`r`n
		MsgBox, %ClipBoard%
		Exit
	}
}
. The GUI works and opens a small window filled with a solid blue/grey. I get the following from ListVars:

Local Variables for ConfirmDesiredPixelAtLocation()
--------------------------------------------------
DesiredColor[8 of 63]: 0x707070
EndTime[9 of 63]: 282375079
Err[1 of 3]: 2
Flag[1 of 3]: 1
LocationComment[18 of 63]: X on workspace tab
LoopTime[4 of 7]: 5000
OutputVarX[0 of 0]:
OutputVarY[0 of 0]:
WindowTitle[0 of 0]:
X[10 of 63]: 333.000000
Xmax[10 of 63]: 335.000000
Xmin[10 of 63]: 331.000000
Y[9 of 63]: 68.000000
Ymax[9 of 63]: 70.000000
Ymin[9 of 63]: 66.000000


Global Variables (alphabetical)
--------------------------------------------------
0[1 of 3]: 0
ErrorLevel[1 of 3]: 2
IsWorkSpaceOpen[0 of 0]:
mycolor[8 of 63]: 0x707070
MyProgress[0 of 0]:
WindowTitle[0 of 0]:

I see that WindowTitle is not defined but am not sure it matters in this simplified version. Any other ideas? In the meantime I'll reboot my machine. Thanks again for your help.

#10 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 03 August 2012 - 06:10 PM

Hi dra,

I realize after reading you post that there were some other steps that I used to get a match.
I actually dragged the gui to where the search was supposed to occur.

A far more rough, but effective way to get a match is to use these lines instead of the 5 I previously listed.
gui, color, 0x707070
gui, show, w%A_ScreenWidth% h%A_ScreenHeight%
return
In reviewing the thread I also realize I lost sight of your goal.
Post subject: Finding the source of ErrorLevel = 2 in PixelSearch
If I combine the 3 lines I just listed above, the script that you just posted,
but replace the function with that of the original post, I get a match.

Hre is my code listing as I have just described it.
Please try it so see if it works for you.
gui, color, 0x707070
gui, show, w%A_ScreenWidth% h%A_ScreenHeight%
return

Gui, Add, Progress,  h100 w400 cBlue vMyProgress, 95
mycolor = 0x707070
guicontrol, +c%mycolor%, MyProgress
gui, show, 
return

^#!z::
CoordMode, ToolTip, screen
CoordMode, Pixel, screen
CoordMode, Mouse, screen

SetTitleMatchMode, Slow
SetWinDelay, 1000
SetControlDelay, 100

IfWorkSpaceOpen:
   IsWorkSpaceOpen := ConfirmDesiredPixelAtLocation(1, WindowTitle, 333, 68, 0x707070, "X on workspace tab", 5000) 
   MsgBox IsWorkSpaceOpen = %IsWorkSpaceOpen%
   Return
   
ConfirmDesiredPixelAtLocation(Flag, WindowTitle, X, Y, DesiredColor, LocationComment, LoopTime)
{
   ;transform the coordinates from 1680 x 1050 resolution to current screen resolution
   X := X//(1680/A_ScreenWidth)
   Y := Y//(1050/A_ScreenHeight)
   Xmin := X-2
   Xmax := X+2 
   Ymin := Y-2 
   Ymax := Y+2
   EndTime := A_TickCount+LoopTime+1
   
   ClipBoard =
   ClipBoard = %ClipBoard% X = %X% `r`n
   ClipBoard = %ClipBoard% Y = %Y% `r`n   
   ClipBoard = %ClipBoard% Xmin = %Xmin% `r`n
   ClipBoard = %ClipBoard% Xmax = %Xmax% `r`n
   ClipBoard = %ClipBoard% Ymin = %Ymin% `r`n
   ClipBoard = %ClipBoard% Ymax = %Ymax% `r`n
   ClipBoard = %ClipBoard% LoopTime = %LoopTime% `r`n
   ClipBoard = %ClipBoard% DesiredColor = %DesiredColor% `r`n
   ClipBoard = %ClipBoard% EndTime = %Endtime% `r`n
   ClipBoard = %ClipBoard% `r`n
   
   While A_TickCount<EndTime 
   {
      PixelSearch, OutputVarX, OutputVarY, Xmin, Ymin, Xmax, Ymax, DesiredColor, 5, Fast
      If ErrorLevel=0
      {
         Return 0
      }
      Sleep 10
   }
   If (Flag=1 and ErrorLevel=1)
   {
      Return 1
   }
   Else If (Flag=0 and ErrorLevel=1)
   {
      WinGetActiveTitle, CurrentTitle
      MouseMove, X, Y
      ;ClipBoard =
      ClipBoard = %ClipBoard%  Problem in ConfirmDesiredPixelAtLocation - Unable to find pixel at %LocationComment%`r`n
      ClipBoard = %ClipBoard% `r`n
      ClipBoard = %ClipBoard% Trying to find %LocationComment% on %WindowTitle%`r`n
      ClipBoard = %ClipBoard% The mouse is currently positioned on the target`r`n
      ClipBoard = %ClipBoard% Search centered at (%X%, %y%) on %CurrentTitle%`r`n
      ClipBoard = %ClipBoard% Search grid is (%Xmin% to %Xmax%, %Ymin% to %Ymax%)`r`n
      ClipBoard = %ClipBoard% `r`n
      ClipBoard = %ClipBoard% The above result is on clipboard `r`n
      ClipBoard = %ClipBoard% Exiting script `r`n
      MsgBox, %ClipBoard%
      Exit
   }
   Else
   {
      WinGetActiveTitle, CurrentTitle
      ;ClipBoard =
      ClipBoard = %ClipBoard% Problem in ConfirmDesiredPixelAtLocation - Invalid ErrorLevel or Flag while attemptng to find %LocationComment%`r`n
      ClipBoard = %ClipBoard% `r`n
      ClipBoard = %ClipBoard% ErrorLevel = |%ErrorLevel%|`r`n
      ClipBoard = %ClipBoard% Flag = |%Flag%|`r`n
      ClipBoard = %ClipBoard% CurrentTitle = |%CurrentTitle%|`r`n
      ClipBoard = %ClipBoard% WindowTitle  = |%WindowTitle%|`r`n
      ClipBoard = %ClipBoard% Valid error levels are 0 & 1.`r`n
      ClipBoard = %ClipBoard% `r`n
      ClipBoard = %ClipBoard% The above result is on clipboard `r`n
      ClipBoard = %ClipBoard% Exiting script `r`n
      MsgBox, %ClipBoard%
      Exit
   }
}






Return

;==================================================================
;==================================================================


;#singleinstance off   ; prevents a message about closing running copy of script
 #singleinstance force   ; prevents a message about closing running copy of script

;#Persistent   ; only needed if there are settimer, but no gui or hotkeys

; my debugging tools are below this line

+esc::      ; <---- easy way to close the script

  exitapp

f11::listvars
f12::reload   ; easy to reload & run the script after changes

Btw, my previous statement is totally bogus.

Using %DesiredColor% is >>essential<<.

You had it correct to begin with; my mistake. :oops:

#11 dra

dra
  • Members
  • 100 posts

Posted 03 August 2012 - 07:26 PM

I really appreciate your help. So your version of the script above works if the GUI color is 0x707070. But if I change the GUI color to 0xB07070 it should result in ErrorLevel=1. Instead it results in:

X = 333.000000
Y = 68.000000
Xmin = 331.000000
Xmax = 335.000000
Ymin = 66.000000
Ymax = 70.000000
LoopTime = 5000
DesiredColor = 0x707070
EndTime = 9176016

Problem in ConfirmDesiredPixelAtLocation - Invalid ErrorLevel or Flag while attemptng to find X on workspace tab

ErrorLevel = |2|
Flag = |1|
CurrentTitle = |t2.ahk|
WindowTitle = ||
Valid error levels are 0 & 1.

The above result is on clipboard
Exiting script


Still baffled. Can you think of something else? P.S. I did the reboot.

#12 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 03 August 2012 - 09:00 PM

Still baffled. Can you think of something else? P.S. I did the reboot.

Yes, baffled.
Let's simplify the script somewhat. Try this version.
Note that the MsgBox IsWorkSpaceOpen will not provide useful data.
However, the msgbox will tell use when the test is complete; so we can paste the clipboard.
gui, color, 0xB07070
gui, show, w%A_ScreenWidth% h%A_ScreenHeight%
return

Gui, Add, Progress,  h100 w400 cBlue vMyProgress, 95
mycolor = 0x707070
guicontrol, +c%mycolor%, MyProgress
gui, show, 
return

^#!z::
f2::
CoordMode, ToolTip, screen
CoordMode, Pixel, screen
CoordMode, Mouse, screen

SetTitleMatchMode, Slow
SetWinDelay, 1000
SetControlDelay, 100

IfWorkSpaceOpen:
   IsWorkSpaceOpen := ConfirmDesiredPixelAtLocation(1, WindowTitle, 333, 68, 0x707070, "X on workspace tab", 5000) 
   MsgBox IsWorkSpaceOpen = %IsWorkSpaceOpen%
   Return
   
ConfirmDesiredPixelAtLocation(Flag, WindowTitle, X, Y, DesiredColor, LocationComment, LoopTime)
{
   ;transform the coordinates from 1680 x 1050 resolution to current screen resolution
   X := X//(1680/A_ScreenWidth)
   Y := Y//(1050/A_ScreenHeight)
   Xmin := X-2
   Xmax := X+2 
   Ymin := Y-2 
   Ymax := Y+2
   EndTime := A_TickCount+LoopTime+1
   
   ClipBoard =
   ClipBoard = %ClipBoard% X = %X% `r`n
   ClipBoard = %ClipBoard% Y = %Y% `r`n   
   ClipBoard = %ClipBoard% Xmin = %Xmin% `r`n
   ClipBoard = %ClipBoard% Xmax = %Xmax% `r`n
   ClipBoard = %ClipBoard% Ymin = %Ymin% `r`n
   ClipBoard = %ClipBoard% Ymax = %Ymax% `r`n
   ClipBoard = %ClipBoard% LoopTime = %LoopTime% `r`n
   ClipBoard = %ClipBoard% DesiredColor = %DesiredColor% `r`n
   ClipBoard = %ClipBoard% EndTime = %Endtime% `r`n
   ClipBoard = %ClipBoard% `r`n
   
   While A_TickCount<EndTime 
   {
      PixelSearch, OutputVarX, OutputVarY, Xmin, Ymin, Xmax, Ymax, DesiredColor, 5, Fast
	err := errorlevel
       ClipBoard = %ClipBoard% Err = %err% `r`n

      If ErrorLevel=0
      {
         Return 0
      }
      Sleep 100
   }
}



Return
My result is as follows.

X = 270.000000 
 Y = 49.000000 
 Xmin = 268.000000 
 Xmax = 272.000000 
 Ymin = 47.000000 
 Ymax = 51.000000 
 LoopTime = 5000 
 DesiredColor = 0x707070 
 EndTime = 12777302 
 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1 
 Err = 1


#13 dra

dra
  • Members
  • 100 posts

Posted 07 August 2012 - 05:42 PM

Thanks for persistence in trying to figure this out.

When I run the code I get:

X = 333.000000
Y = 68.000000
Xmin = 331.000000
Xmax = 335.000000
Ymin = 66.000000
Ymax = 70.000000
LoopTime = 5000
DesiredColor = 0x707070
EndTime = 21900797

Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2
Err = 2


and the MsgBox says:

IsWorkSpaceOpen =


More baffled. Can you think of something else? Thanks.

#14 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 07 August 2012 - 09:02 PM

I use both AHK-basic and AHK_L. I use AHL suffix for AHK_L scripts and AHK for AHK_basic scripts.

It appears that the err= 2 is caused by 'fast' using AHK_L, when the colors don't match.
If I run this same exact script with ahk_basic, the '2' become '1'
It would seem to be a bug in AHK_L
DesiredColor = 0x707070
OtherColor = 0xB07070

CoordMode, ToolTip, screen
CoordMode, Pixel, screen
CoordMode, Mouse, screen

x = 100
y = 100

result := A_ScriptName "  version " A_AhkVersion "`r`r" 

backgroundcolor := DesiredColor

gui, destroy
gui, color, %backgroundcolor%

result .= "background is " backgroundcolor "`r"
result .= "DesiredColor " DesiredColor  

gui, -Caption
gui, show, w%A_ScreenWidth% h%A_ScreenHeight%

 

 PixelGetColor, color, X, Y 

 PixelSearch, OutputVarX, OutputVarY, x,y,x,y, DesiredColor, 5, Fast
 err_5_fast := errorlevel

 PixelSearch, OutputVarX, OutputVarY, x,y,x,y, DesiredColor, 0, Fast
 err_0_fast := errorlevel

 PixelSearch, OutputVarX, OutputVarY, x,y,x,y, DesiredColor, 5, 
 err_5____ := errorlevel

 PixelSearch, OutputVarX, OutputVarY, x,y,x,y, DesiredColor, 
 err_0___ := errorlevel

 result .= "`rPixelGetColor " color "`rerr_5_fast= " err_5_fast "`rerr_0___= " err_0___
 result .= "`rerr_5____= " err_5____ "`rerr_0_fast= " err_0_fast

;==============================================================
 result .= "`r`r"
sleep, 1000
;==============================================================
backgroundcolor := OtherColor

gui, destroy
gui, color, %backgroundcolor%

result .= "background is " backgroundcolor "`r"
result .= "DesiredColor " DesiredColor  

gui, -Caption
gui, show, w%A_ScreenWidth% h%A_ScreenHeight%

 PixelGetColor, color, X, Y 

 PixelSearch, OutputVarX, OutputVarY, x,y,x,y, DesiredColor, 5, Fast
 err_5_fast := errorlevel

 PixelSearch, OutputVarX, OutputVarY, x,y,x,y, DesiredColor, 0, Fast
 err_0_fast := errorlevel

 PixelSearch, OutputVarX, OutputVarY, x,y,x,y, DesiredColor, 5, 
 err_5____ := errorlevel

 PixelSearch, OutputVarX, OutputVarY, x,y,x,y, DesiredColor, 
 err_0___ := errorlevel

 result .= "`rPixelGetColor " color "`rerr_5_fast= " err_5_fast "`rerr_0___= " err_0___
 result .= "`rerr_5____= " err_5____ "`rerr_0_fast= " err_0_fast

sleep, 1000
gui, destroy

msgbox % result

Return



Return
junk2681a.ahl  version 1.1.07.03

background is 0x707070
DesiredColor 0x707070
PixelGetColor 0x707070
err_5_fast= 0
err_0___= 0
err_5____= 0
err_0_fast= 0

background is 0xB07070
DesiredColor 0x707070
PixelGetColor 0x7070B0
err_5_fast= 2
err_0___= 1
err_5____= 1
err_0_fast= 2


#15 dra

dra
  • Members
  • 100 posts

Posted 08 August 2012 - 03:08 PM

I get the same thing:

t00.ahk version 1.1.07.03

background is 0x707070
DesiredColor 0x707070
PixelGetColor 0x707070
err_5_fast= 0
err_0___= 0
err_5____= 0
err_0_fast= 0

background is 0xB07070
DesiredColor 0x707070
PixelGetColor 0x7070B0
err_5_fast= 2
err_0___= 1
err_5____= 1
err_0_fast= 2


I presume you will report the bug. Thanks again for all of your help.