Help with "Pixelsearch" command

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
exaltedsmith
Posts: 2
Joined: 09 Feb 2018, 04:46

Help with "Pixelsearch" command

09 Feb 2018, 05:03

Here is part of my code:

{
PixelSearch, FoundX, FoundY, 474, 999, 535, 1059, 0x71ABBD, 0, Fast RGB
PixelSearch, FoundX, FoundY, 472, 1000, 538, 1061, 0x4B3939, 0, Fast RGB
PixelSearch, FoundX, FoundY, 475, 1000, 539, 1062, 0xA05531, 0, Fast RGB
if ErrorLevel = 0
{
Send, +3
Sleep, 150
}
PixelSearch, FoundX, FoundY, 475, 1001, 535, 1059, 0xF4E896, 0, Fast RGB
PixelSearch, FoundX, FoundY, 475, 1000, 537, 1059, 0x730C94, 0, Fast RGB
PixelSearch, FoundX, FoundY, 476, 1001, 537, 1058, 0x1E201E, 0, Fast RGB
if ErrorLevel = 0
{
Send, +4
Sleep, 150
}



Usually I just work with something like this:

PixelSearch, FoundX, FoundY, 474, 999, 535, 1059, 0x71ABBD, 0, Fast RGB
if ErrorLevel = 0
{
Send, +3
Sleep, 150
}


And that works out just fine, however this time around the profile I'm working on has several 'icons' that have pixels in the similar position or area with a similar color. So what ends up happening is when I have a script that's searing for a pixel and it finds it in two different icons, it will press both +3 and +4 instead of just one button like it's supposed to.

So the work around I'm looking for is for each icon, I'm trying to make the script search for 3 pixels instead of just 1 pixel in an area, and only if it finds all 3 of those pixels will it press the button. However using the script linked on the top, I still get two button presses when icons have similar pixels.

Here's what I'm looking for:

PixelSearch, FoundX, FoundY, 474, 999, 535, 1059, 0x71ABBD, 0, Fast RGB (SEARCH FOR THIS PIXEL HERE)
(AND)
PixelSearch, FoundX, FoundY, 472, 1000, 538, 1061, 0x4B3939, 0, Fast RGB (SEARCH FOR THIS PIXEL HERE)
(AND)
PixelSearch, FoundX, FoundY, 475, 1000, 539, 1062, 0xA05531, 0, Fast RGB (SEARCH FOR THIS PIXEL HERE)
if ErrorLevel = 0 (IF ALL 3 PIXELS ARE FOUND IN THEIR SPOTS THEN SEND +3)
{
Send, +3
Sleep, 150
}


Can someone help me figure out the "And" condition on this pixel search script so I can make it work as intended?
User avatar
boiler
Posts: 16949
Joined: 21 Dec 2014, 02:44

Re: Help with "Pixelsearch" command

09 Feb 2018, 09:27

It seems it would be faster, easier, and more reliable to use ImageSearch for a piece of the icon you're looking for rather than checking for several pixels.

To do it the way you're trying to do it, try this:

Code: Select all

PixelSearch, FoundX, FoundY, 474, 999, 535, 1059, 0x71ABBD, 0, Fast RGB
PixelError := ErrorLevel
PixelSearch, FoundX, FoundY, 472, 1000, 538, 1061, 0x4B3939, 0, Fast RGB
PixelError += ErrorLevel
PixelSearch, FoundX, FoundY, 475, 1000, 539, 1062, 0xA05531, 0, Fast RGB
PixelError += ErrorLevel
if (PixelError = 0) ; will be true only if all three ErrorLevel results were 0
{
	Send, +3
	Sleep, 150
}
IHAT
Posts: 10
Joined: 09 Feb 2018, 09:59

Re: Help with "Pixelsearch" command

09 Feb 2018, 10:15

Hello,

first I would like to thank you for the great PMC.

I managed to use it to create a simple macro loop and take action based on the image found

Loop
{
Loop
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 1085, 222, 1178, 328, C:\Users\Elite\AppData\Roaming\MacroCreator\Screenshots\Screen_20180206041018.png
CenterImgSrchCoords("C:\Users\Elite\AppData\Roaming\MacroCreator\Screenshots\Screen_20180206041018.png", FoundX, FoundY)
If ErrorLevel = 0
Click, %FoundX%, %FoundY%, 0
}
Until ErrorLevel = 0
Click, 41, 217 Left, 1
Sleep, 5
Click, 46, 188 Left, 1
Sleep, 500
Loop
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 1085, 222, 1178, 328, C:\Users\Elite\AppData\Roaming\MacroCreator\Screenshots\Screen_20180206041108.png
}
Until ErrorLevel = 0
Click, 38, 217 Left, 1
Sleep, 2000
Click, 91, 186 Left, 1
Sleep, 500
}

now I want to develop this macro into a complicated one and make use "if not found"
the way i think of it
macro 1
image found the loop is on going
image not found - the mouse to click on the PMC bar to start Macro 2
then run macro 2 till the image is not found then the mouse to click the PMC control bar to back button to start macro one again.

is it possible or is there an easier way to do it.
i have 2 windows tiled on the screen, the window to the right is the trigger of macro 1 & 2, and based on the running macro the orders mouse clicks will be executed on the left side window.

Appreviate your reply
User avatar
boiler
Posts: 16949
Joined: 21 Dec 2014, 02:44

Re: Help with "Pixelsearch" command

09 Feb 2018, 10:58

@IHAT: Looks like you posted in the wrong thread. It is unrelated to the topic of this thread, and neither of us are Pulover, who is the author of PMC.
IHAT
Posts: 10
Joined: 09 Feb 2018, 09:59

Re: Help with "Pixelsearch" command

09 Feb 2018, 14:39

[quote="boiler"]@IHAT: Looks like you posted in the wrong thread. It is unrelated to the topic of this thread, and neither of us are Pulover, who is the author of PMC.[/quo

Sorry PMC=Pullover's Macro creator

Kindly help to where to go in the forum to create the right macro

i changed the approach and created a loop within loop but the problem is still the action if not found

Loop
{
Loop
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 1215, 240, 1584, 453, C:\Users\Elite\AppData\Roaming\MacroCreator\Screenshots\Screen_20180209195207.png
If ErrorLevel
Break
}
Until ErrorLevel
Loop, 1
{
Loop
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 479, 241, 847, 461, C:\Users\Elite\AppData\Roaming\MacroCreator\Screenshots\Screen_20180209200833.png
CenterImgSrchCoords("C:\Users\Elite\AppData\Roaming\MacroCreator\Screenshots\Screen_20180209200833.png", FoundX, FoundY)
If ErrorLevel = 0
Click, %FoundX%, %FoundY%, 0
}
Until ErrorLevel = 0
Click, 51, 246 Left, 1
Sleep, 5
Click, 54, 221 Left, 1
Sleep, 500
Loop
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 483, 242, 835, 457, C:\Users\Elite\AppData\Roaming\MacroCreator\Screenshots\Screen_20180209201123.png
If ErrorLevel = 0
Click, %FoundX%, %FoundY%, 0
}
Until ErrorLevel = 0
Click, 53, 244 Left, 1
Sleep, 100
}
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 1230, 234, 1566, 446, C:\Users\Elite\AppData\Roaming\MacroCreator\Screenshots\Screen_20180209201030.png
Loop, 1
{
Loop
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 453, 221, 837, 471, C:\Users\Elite\AppData\Roaming\MacroCreator\Screenshots\Screen_20180209201235.png
CenterImgSrchCoords("C:\Users\Elite\AppData\Roaming\MacroCreator\Screenshots\Screen_20180209201235.png", FoundX, FoundY)
If ErrorLevel = 0
Click, %FoundX%, %FoundY%, 0
If ErrorLevel
{
MsgBox, 49, Continue?, Image / Pixel Not Found.`nPress OK to continue.
IfMsgBox, Cancel
Return
}
}
Until ErrorLevel = 0
Click, 45, 247 Left, 1
Sleep, 5
Click, 99, 219 Left, 1
Sleep, 500
Loop
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 486, 235, 843, 461, C:\Users\Elite\AppData\Roaming\MacroCreator\Screenshots\Screen_20180209202826.png
}
Until ErrorLevel = 0
Click, 49, 245 Left, 1
Sleep, 100
}
}


thanks for your help
exaltedsmith
Posts: 2
Joined: 09 Feb 2018, 04:46

Re: Help with "Pixelsearch" command

12 Feb 2018, 01:33

boiler wrote:It seems it would be faster, easier, and more reliable to use ImageSearch for a piece of the icon you're looking for rather than checking for several pixels.

To do it the way you're trying to do it, try this:

Code: Select all

PixelSearch, FoundX, FoundY, 474, 999, 535, 1059, 0x71ABBD, 0, Fast RGB
PixelError := ErrorLevel
PixelSearch, FoundX, FoundY, 472, 1000, 538, 1061, 0x4B3939, 0, Fast RGB
PixelError += ErrorLevel
PixelSearch, FoundX, FoundY, 475, 1000, 539, 1062, 0xA05531, 0, Fast RGB
PixelError += ErrorLevel
if (PixelError = 0) ; will be true only if all three ErrorLevel results were 0
{
	Send, +3
	Sleep, 150
}
Thank you very much, I will try this out.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mebelantikjaya, OrangeCat and 293 guests