Pixel Predator - PixelSearch Script

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Pixel Predator - Pixel Search Script

26 Oct 2019, 15:02

Thanks for the secret version 8-)
Hellbent wrote:
26 Oct 2019, 02:30
I'm not a hotkey guy, don't like having to remember them, don't like having to twist my wrists to press them, don't like having to take my hand off my mouse to press them.
that's not the point, I also like to use the mouse but what if you want to set for ex. 2 clicks per loop and a waiting time of 211 milli sec... how would you do that if numpad 2 and 1 are disabled ? :think: use the others 1 and 2 keys :sick: ?
I'm a numpad guy and I like to use the numpad to enter values like tons of other users and if a first user can't enter a value like "1221" in notepad, he'll think your script is a harmful script :!: .

suggestions:
  • Single Pixel Search Area.
    this is not how it should be, the tpx and tpy positions of the chosen color must be retained as global values.
    These values will then be used to define the 1x1 region.

    first define tpx and tpy as global values

    Code: Select all

    global tpx, tpy, HB_Button:=[],Selected_Color:="610094",Color_Edit:="0x610094",Stop:=1,X_Pos:="",Y_Pos:="",W_Pos:="",H_Pos:="",cx2:="",cy2:="",cx:="",cy:="",Variation:=0,RTimes:=1,CMove:=1,CTimes:=1,XOff:=10,YOff:=10,TypeC:="Left",Send_Stuff:="",M_Delay:=30,Key_Delay:=30,Delay:=500
    
    then replaces the function SetPixel() with this one

    Code: Select all

    SetPixel(){
    	if (!tpx) {
    		msgbox,262144,, Please set a color first
    		return
    	}
    	X_Pos:=tpx, Y_pos:=tpy
    	GuiControl,1:,X_Pos, % tpx
    	GuiControl,1:,Y_Pos, % tpy	
    	cx2:=X_Pos,cy2:=Y_Pos
    	GuiControl,1:,W_Pos,1
    	GuiControl,1:,H_Pos,1
    }
    
Hellbent wrote:
26 Oct 2019, 02:30
button on/off to toggle loop
Not clear on what you mean.
For my personal use I had created a second GUI for the settings (not very nice but it does the job)
example of key to show the second gui

Code: Select all

f2::QuickSettings()
Here is the second hidden GUI

Code: Select all

gui 2: +AlwaysOnTop -SysMenu
Gui, 2:Add,Checkbox, x10 y10 vRtimes Checked%Rtimes%, Search Loop
Gui, 2:Add,Checkbox, x10 y+3 vCMove Checked%CMove%, Want Click
Gui, 2:Add,edit, x10 y+3 w50 h20 -WantReturn cblack 0x201 vCTimes, 1
gui, 2:add, updown,  Range1-1000, 1
Gui, 2:Add,text, x+3 yp h20 -border 0x201, Number of Clicks Per Loop
Gui, 2:Add,edit, x10 y+3 w50 h20 -WantReturn cblack 0x201 vXOff, 0
gui, 2:add, updown,  Range0-10000, 0
Gui, 2:Add,text, x+3 yp h20 -border 0x201, X-Offset (Click & Move)
Gui, 2:Add,edit, x10 y+3 w50 h20 cblack -WantReturn 0x201 vYOff, 0
gui, 2:add, updown, Range0-10000, 0
Gui, 2:Add,text, x+3 yp h20 -border 0x201, Y-Offset (Click & Move)
mbuttons:=["L","M","R"]
Gui, 2:Add,edit, x10 y+3 w35 h20 cblack -WantReturn center vTypeC, % mbuttons[1]
Gui, 2:Add,text, x+15 yp w0 h20 -border   0x201,
gui, 2:add, updown, Range1-3 vMBtxt gMB,
Gui, 2:Add,text, x+3 yp h20 -border  0x201, Which Mouse Button to use (Values: L, M, R)
Gui, 2:Add,edit, x10 y+3 w50 h20 cblack -WantReturn vM_Delay,
gui, 2:add, updown, Range0-10000, 30
Gui, 2:Add,text, x+3 yp h20 -border 0x201, Amount of time a click is held (in ms)
Gui, 2:Add,edit, x10 y+3 w50 h20 cblack -WantReturn vKey_Delay,
gui, 2:add, updown, Range0-10000, 30
Gui, 2:Add,text, x+3 yp h20 -border 0x201 , Amount of time between key strokes (in ms)
Gui, 2:Add,edit, x10 y+3 w50 h20 -WantReturn vDelay, 500
gui, 2:add, updown, Range0-100000, 500
Gui, 2:Add,text, x+3 yp h20 -border 0x201, Loop Delay (Delay between Search Loops (in ms)
Gui, 2:Add,text, x10 y+3 h20 -border 0x201, Commands to "send" (e.g. {Enter} r)
Gui, 2:Add,edit, x10 y+3 w300 h50 cblack cblack -WantReturn vSend_Stuff,
Gui, 2:font
Gui, 2:Add,button, x10 y+3 gapply, Apply

QuickSettings(){
gui 2: show
}
apply() {
gui 2: submit
	GuiControl,1:,Commands,% ComLDel RTimes ComLDel CMove ComLDel CTimes ComLDel XOff ComLDel YOff ComLDel TypeC ComLDel M_Delay ComLDel Key_Delay ComLDel Delay ComLDel Send_Stuff
return
}
MB() {
	global
	gui, 2: submit, nohide
	guicontrol,, TypeC, % mbuttons[MBtxt]
}

Let me know if it works. :roll:
Cheers.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pixel Predator - Pixel Search Script

27 Oct 2019, 04:21

SpeedMaster wrote:
26 Oct 2019, 15:02
Thanks for the secret version 8-)
:silent: shhh. It's topsy kret :silent:
button on/off to toggle loop
I thought that was what you meant. I actually had wrote out a response with that as the assumed meaning, but decided to make sure that is what you were talking about first.

When I first started designing the interface for this script one of my goals was to keep the number of controls down, with the reason being two-fold. First, it would keep the size of the interface small and unobtrusive, and second, it would present a new user with something that wasn't intimidating.
Sure the command line does take a min to get used to, but it packs it all down into a single control.

That said. I do like the idea of having that optional pop-up window while still keeping the command line. I don't think that i'll be adding it to this version because I would have to design a new window for it and figure out how I want to have it launched, so I think that it will have to wait for version 1.3. However there is nothing stopping you from sharing your altered version of the script with the pop-up that you made. If you do, i'll add something to the new OP directing readers to your post.

For some context. Here is a image of my early design work for Version 2 which I had done shortly before working on v1.2.1 (May)
Even with all the controls it has, it doesn't reflect how many it would actually need (don't know why I decided to prototype in a custom window :? )
Spoiler
use the others 1 and 2 keys :sick: ?
Inconceivable :roll:
I'm a numpad guy and I like to use the numpad to enter values like tons of other users and if a first user can't enter a value like "1221" in notepad, he'll think your script is a harmful script :!:
By its very nature, this is a potentially harmful script. After all it does take control of your cursor and send keystrokes (and as of yesterday it also uses the Run command, the WinClose Command and the SoundPlay Command). Up until yesterday the user would have to at the very least set the command line for the script to do anything at all, In fact, if the command line isn't set and you try to run it you'll get a error message (I also normally code in a check to make sure the position coords are set in these types of scripts, but it seems I didn't with this one). So how on earth is someone going to have looked up how the command line works, set a position and color or set the error level check without checking the hotkeys and info? It's the biggest button on the interface!!! Opening the Hotkey window is also the first thing I do in the demo video. Version 1.1 had the hotkeys hard coded, I changed that and added the ability for the user to change them on the fly. I have also now made it so that the user can easily find and change the defaults at the top of the script.
While I'm always open for debate on pretty much anything, I really don't think my opinion on this is going to change. Numpad1 and Numpad2 are the default hotkeys. I like them that way, and unless a better argument can be presented they are going to stay that way.

I had to use my panic key (AHK script killer) the first time I tested the script ;) (I had no idea that you had to press the number pad 2 to stop the script) :?
Now I'm not trying to be rude, or make some profound statement, or point fingers here, but... that was your fault, not mine.
You went through all the steps of setting the script up without even checking what the hotkeys were. That's on you bro. 8-)

suggestions:
Single Pixel Search Area.
this is not how it should be, the tpx and tpy positions of the chosen color must be retained as global values.
These values will then be used to define the 1x1 region.
"this is not how it should be". That's not really factual. Often the user will have to rely on a screenshot or some other method to get the color they need to use as it isn't necessarily going to be present at any given moment. I think what I'll do is take what I added to the [ set position ] button and add the same sort of thing to the [ set color ] button as well. That way when you set the color you also set the position. I'll add it in and update the post within the next few days.


As always, it was nice to hear your feedback Speed.
User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Pixel Predator - Pixel Search Script

27 Oct 2019, 13:10

speedmaster wrote:I had to use my panic key (AHK script killer) the first time I tested the script ;) (I had no idea that you had to press the number pad 2 to stop the script)
Hellbent wrote:
27 Oct 2019, 04:21
...So how on earth is someone going to have looked up how the command line works, set a position and color or set the error level check without checking the hotkeys and info? It's the biggest button on the interface!!!
Now I'm not trying to be rude, or make some profound statement, or point fingers here, but... that was your fault, not mine. You went through all the steps of setting the script up without even checking what the hotkeys were. That's on you bro.
No I don't think so :problem: . I was used to using your old version (v1.0.1) and in the old version the keyboard shortcuts were ctrl+esc to exit the program and esc to stop the script.
Hellbent wrote:
27 Oct 2019, 04:21
Here is a image of my early design work for Version 2 which I had done shortly before working on v1.2.1 (May)
It looks promising 8-)

Cheers,
Last edited by SpeedMaster on 26 Sep 2021, 11:20, edited 1 time in total.
FreakyDoctor
Posts: 3
Joined: 01 Dec 2019, 17:08

Re: Pixel Predator - PixelSearch Script

02 Dec 2019, 07:44

Hello i have Orage and Red colors, On orage color he's pressing button Color_Edit:="0xF66208" But. with Orange Color Sometimes Can be Red color, and of course he's still reacting on orange. I need to make him not react on orange if with Orange color will be Red color.

I'l added 2 colors here first and second (Orange and Red)

Code: Select all

global HB_Button:=[],Selected_Color:="0xFF3530",Color_Edit:="0xFF3530",Color_Edit2:="0xF66208",Selected_Color2:="0xF66208",Stop:=1,X_Pos:="",Y_Pos:="",W_Pos:="",H_Pos:="",cx2:="",cy2:="",cx:="",cy:="",Variation:=0,RTimes:=1,CMove:=1,CTimes:=1,XOff:=10,YOff:=10,TypeC:="Left",Send_Stuff:="",M_Delay:=10,Key_Delay:=10,Delay:=500
Now pixelsearch function

Code: Select all

Start_Search(){
	Stop:=0
	HB_Button[10].Draw_Active()
	if(!SortCommandList())
		return
	GuiControlGet,Color_Edit,1:,Color_Edit,Color_Edit2,1:,Color_Edit2
        GuiControlGet,Variation,1:,Variation  
	While(!Stop){
		PixelSearch,px,py,X_Pos,Y_Pos,cx2,cy2,Color_Edit,Variation,Fast|RGB
		if(!ErrorLevel&&Truth[1].State=1){
			if(CMove=1)
				Click_Function(px+XOff,py+YOff,CTimes,TypeC)
			else if(CMove="Beep"){
				Loop,% CTimes	{
					SoundBeep,600
					if(Stop){
						return
					}
				}
			}else if(CMove=0&&CTimes>=1)
				Move_Function(px+XOff,py+YOff)
			if(Send_Stuff){
				if(Substr(Send_Stuff,1,5)="[RUN]"){
					RunStuff()
					Stop_Search()
					return
				}else if(Substr(Send_Stuff,1,7)="[close]"){
					CloseStuff()
					Stop_Search()
					return
				}else if(Substr(Send_Stuff,1,7)="[Sound]"){
					SoundStuff()
					if(RTimes=0){
						Stop_Search() 
						return
					}
					continue
				}
				Send_Function(Send_Stuff)
			}
			if(RTimes=0){
				Stop_Search() 
				return
			}
			Sleep,% Delay
		}else if(ErrorLevel=1&&Truth[2].State=1){
			if(CMove="Beep"){
				Loop,% CTimes	{
					SoundBeep,600
					if(Stop){
						return
					}
				}
			}
			if(Send_Stuff){
				if(Substr(Send_Stuff,1,5)="[RUN]"){
					RunStuff()
					Stop_Search()
					return
				}else if(Substr(Send_Stuff,1,7)="[close]"){
					CloseStuff()
					Stop_Search()
					return
				}else if(Substr(Send_Stuff,1,7)="[Sound]"){
					SoundStuff()
					if(RTimes=0){
						Stop_Search() 
						return
					}
					continue
				}
				Send_Function(Send_Stuff)
			}
			if(RTimes=0){
				Stop_Search() 
				return
			}
			Sleep,% Delay
		}
	}
}
What i change and add here ? something like this?

Code: Select all

PixelSearch,px,py,X_Pos,Y_Pos,cx2,cy2,Color_Edit,Variation,Fast|RGB
If ErrorLevel = 0
    one := true
else
   one := false
PixelSearch,px1,py1,X_Pos,Y_Pos,cx2,cy2,Color_Edit2,Variation,Fast|RGB
If ErrorLevel = 0
    two := true
else
   two := false
 
If (one) and (two)
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pixel Predator - PixelSearch Script

07 Dec 2019, 12:07

@FreakyDoctor

This script wasn't meant to be altered / used for what you are trying to do with it. Even my planned future versions likely wouldn't include the logic or control interface to combine the results of multiple search results (I'll think about it). I'd suggest that you just create your own search script.
If you omit adding a gui etc. you can have yourself a hotkey script up and running in as little as 10 - 15 mins.
FreakyDoctor
Posts: 3
Joined: 01 Dec 2019, 17:08

Re: Pixel Predator - PixelSearch Script

07 Dec 2019, 18:11

i did it by myself btw is that looks good?

Code: Select all

Start_Search(){
        Stop:=0
        BTimes:=0
        OTimes:=0
	HB_Button[10].Draw_Active()
	if(!SortCommandList())
		return
	GuiControlGet,Color_Edit,1:,Color_Edit,Color_Edit2,1:,Color_Edit2
        GuiControlGet,Variation,1:,Variation
        While(!Stop){
	PixelSearch,px,py,X_Pos,Y_Pos,cx2,cy2,Color_Edit2,Variation,Fast|RGB
        if(ErrorLevel = 0)
        BTimes:=1
        if(ErrorLevel = 1)
        BTimes:=2
if(BTimes=1)
msgbox, Warrning! Orange color was found!
if(BTimes=2)
msgbox, Error.. orange color was not found!
         PixelSearch,px2,py2,X_Pos,Y_Pos,cx2,cy2,Color_Edit,Variation,Fast|RGB
         if(ErrorLevel = 0)
         OTimes:=1
         if(ErrorLevel = 1)
         OTimes:=2
if(OTimes=1)
msgbox, Warrning! Red color was found!
if(OTimes=2)
msgbox, Red color was not found!
if(BTimes=1&&OTimes>=2)
msgbox, PEW PEW PEW!
if(BTimes=1&&OTimes>=2)
Click_Function(px+XOff,py+YOff,CTimes,TypeC)
}
}
}
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pixel Predator - PixelSearch Script

08 Dec 2019, 12:36

FreakyDoctor wrote:
07 Dec 2019, 18:11
i did it by myself btw is that looks good?

Code: Select all

Start_Search(){
        Stop:=0
        BTimes:=0
        OTimes:=0
	HB_Button[10].Draw_Active()
	if(!SortCommandList())
		return
	GuiControlGet,Color_Edit,1:,Color_Edit,Color_Edit2,1:,Color_Edit2
        GuiControlGet,Variation,1:,Variation
        While(!Stop){
	PixelSearch,px,py,X_Pos,Y_Pos,cx2,cy2,Color_Edit2,Variation,Fast|RGB
        if(ErrorLevel = 0)
        BTimes:=1
        if(ErrorLevel = 1)
        BTimes:=2
if(BTimes=1)
msgbox, Warrning! Orange color was found!
if(BTimes=2)
msgbox, Error.. orange color was not found!
         PixelSearch,px2,py2,X_Pos,Y_Pos,cx2,cy2,Color_Edit,Variation,Fast|RGB
         if(ErrorLevel = 0)
         OTimes:=1
         if(ErrorLevel = 1)
         OTimes:=2
if(OTimes=1)
msgbox, Warrning! Red color was found!
if(OTimes=2)
msgbox, Red color was not found!
if(BTimes=1&&OTimes>=2)
msgbox, PEW PEW PEW!
if(BTimes=1&&OTimes>=2)
Click_Function(px+XOff,py+YOff,CTimes,TypeC)
}
}
}
This is wrong.

Code: Select all

GuiControlGet,Color_Edit,1:,Color_Edit,Color_Edit2,1:,Color_Edit2
Change it to:

Code: Select all

GuiControlGet, Color_Edit , 1: , Color_Edit
GuiControlGet, Color_Edit2 , 1: , Color_Edit2

;or just ( I personally like doing it the way it is above )

GuiControlGet, Color_Edit    ;Pretty sure this should work, I always do it the way I have above.
GuiControlGet, Color_Edit2

Your indentation is pretty bad, but other than that I can't see anything that stands out as wrong.
ToddA1
Posts: 1
Joined: 25 Dec 2019, 08:48

Re: Pixel Predator - PixelSearch Script

26 Dec 2019, 12:01

this is an awesome script. Is there a way to run it without it taking control of the mouse? So that I can still work in other windows while this script runs in its own window.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pixel Predator - PixelSearch Script

07 Jan 2020, 21:12

ToddA1 wrote:
26 Dec 2019, 12:01
this is an awesome script. Is there a way to run it without it taking control of the mouse? So that I can still work in other windows while this script runs in its own window.
This script would need to be modified a fair amount to make that possible so I'd suggest that you look into how to use ControlClick and ControlSend and test if the target app responds to them before you do anything else. If they work, you can then create a simple pixelSearch script of your own. If you omit the gui, or just make a simple one, this would / could be a 30-60min project.
sipureysafta
Posts: 2
Joined: 07 Mar 2020, 18:32

Re: Pixel Predator - PixelSearch Script

07 Mar 2020, 18:46

****editing- I figured it! just found where to edit it in the code, thanks a lot again for this beutiful script*****
Hello! this script is really really great! is there a way to save instances of the script with specific color, search area, code line and hotkeys as default settings? it could be awesome for an interesting project i'm working on :) thank you
sipureysafta
Posts: 2
Joined: 07 Mar 2020, 18:32

Re: Pixel Predator - PixelSearch Script

15 Jun 2020, 06:59

Hi!
this is a really great script!
i'm a little new to AHK,
i really need to be able to save default settings. so i found out how to set the default color in the code, as well as the command line which I edited in the code and the true/false position which I just changed from 0 to 1 and vice versa.
the only thing I didn't manage is to set a default "search area". I tried changing the Gui setting of it to numbers like this:

HB_Button.Push( New HB_Flat_Rounded_Button_Type_1( x:=30 , y := 97 , w := 100 , h := 30 , Button_Color := "22005C" , Button_Background_Color := "333333" , Text := "Set Search Area" , Font := "Arial" , Font_Size := 10 " Bold" , Font_Color_Top := "aaaaaa" , Font_Color_Bottom := "000000" , Window := "1" , Label := "Set_Position" , Default_Button := 0 , Roundness:=2 ) )
Gui,1:Add,Edit, x175 y100 w40 h22 Center ReadOnly vX_Pos,300
Gui,1:Add,Edit, x245 y100 w40 h22 Center ReadOnly vY_Pos,400
Gui,1:Add,Edit, x315 y100 w40 h22 Center ReadOnly vW_Pos,200
Gui,1:Add,Edit, x385 y100 w40 h22 Center ReadOnly vH_Pos,200

but it didn't work.the numbers in the gui did change but it works only if i select the search area in the regular way. if someone can advise me how to do it, or either how to save settings from last operation it would be wonderful!
thank you!
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pixel Predator - PixelSearch Script

15 Jun 2020, 21:54

@sipureysafta

You can hardcode the search area by setting the following variables up near the top of the script.

Code: Select all

X_Pos 	; (X1)
Y_Pos 	; (Y1)
cx2    	; (X2)
cy2    	; (Y2)
shafez
Posts: 1
Joined: 13 Aug 2021, 07:29

Re: Pixel Predator - PixelSearch Script

29 Aug 2021, 17:33

Hello,
Is it possible to make it click once on specific color until color change its location to a different pixel by 1 cm from previous location?
I dont want it to click more than once on same location
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pixel Predator - PixelSearch Script

08 Sep 2021, 13:46

shafez wrote:
29 Aug 2021, 17:33
Hello,
Is it possible to make it click once on specific color until color change its location to a different pixel by 1 cm from previous location?
I dont want it to click more than once on same location
This doesn't do search patterns or logic like that.

You would need to code that yourself.
viewforum.php?f=76
Rayleigh001
Posts: 5
Joined: 26 Sep 2021, 05:59

Re: Pixel Predator - PixelSearch Script

26 Sep 2021, 06:09

Hi, I saw this project in the Youtube and it was amazing. I think it will be better if you could add options to add additional pixel to find if the first pixel was not found, or to find more conditional additional pixel after the first pixel was found. I also wondering if you could add a "sleep" option before the first click. Thank you and may God bless you on your amazing work.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pixel Predator - PixelSearch Script

26 Sep 2021, 10:26

Rayleigh001 wrote:
26 Sep 2021, 06:09
Hi, I saw this project in the Youtube and it was amazing. I think it will be better if you could add options to add additional pixel to find if the first pixel was not found, or to find more conditional additional pixel after the first pixel was found. I also wondering if you could add a "sleep" option before the first click. Thank you and may God bless you on your amazing work.
Thank you.

You can have the sleep come before the search by taking this function and replacing the old one with it . (three small changes)

Code: Select all

Start_Search(){
	Stop:=0
	if(!SortCommandList())
		return
	GuiControlGet,Color_Edit,1:,Color_Edit
	GuiControlGet,Variation,1:,Variation 
	While(!Stop){
		Sleep,% Delay
		PixelSearch,px,py,X_Pos,Y_Pos,cx2,cy2,Color_Edit,Variation,Fast|RGB
		if(!ErrorLevel&&Truth[1].State=1){
			if(CMove=1)
				Click_Function(px+XOff,py+YOff,CTimes,TypeC)
			else if(CMove=0&&CTimes>=1)
				Move_Function(px+XOff,py+YOff)
			if(Send_Stuff)
				Send_Function(Send_Stuff)
			if(RTimes=0){
				Stop:=1
				return
			}
			
		}else if(ErrorLevel=1&&Truth[2].State=1){
			if(Send_Stuff)
				Send_Function(Send_Stuff)
			if(RTimes=0){
				Stop:=1
				return
			}
			
		}
	}
}
I had started on a multi color pixel search script a few years ago but ended up getting distracted with life or something and never went back to it.
I likely will get around to it sooner or later but I have no idea when that will be. Your best bet is to write out your own. That way it does exactly what you want and nothing more.
darkfear42
Posts: 3
Joined: 20 Nov 2021, 10:33

Re: Pixel Predator - PixelSearch Script

20 Nov 2021, 10:51

hi hellbent, your code is very impressive and thank you so much for creating it. I have a few questions that i hope you could help with

1. I would like to always fix the position to (X: 899, Y:855, W:20, H:2) and color to 0xBBF8FE, variation 5. Please let me know if this amendment to your code is correct

Code: Select all

global HB_Button:=[],Selected_Color:="BBF8FE",Color_Edit:="0xBBF8FE",Stop:=1,X_Pos:="899",Y_Pos:="855",W_Pos:="20",H_Pos:="2",cx2:="",cy2:="",cx:="",cy:="",Commands:="",Variation:=5,Start_Key :="Numpad1",Stop_Key:="Numpad2",RTimes:=1,CMove:=1,CTimes:=1,XOff:=10,YOff:=10,TypeC:="Left",Send_Stuff:="",M_Delay:=30,Key_Delay:=30,Delay:=500
2. I want it to press D after detecting the color so I selected the T version. I would like to add a rand sleep of 450ms to 580ms after detecting the color, and a fixed sleep of 2000ms after execution of keypress D before restarting the whole process. Please advise how should I amend the code so that I can make it the default every time i start pixel hunter 1) Default to text version 2) Detect color then Rand sleep of 450 to 580ms, 3) keypress D, 4) fixed sleep 2000ms

I know there might be a simpler way to code this but as a noob I haven't been able to do it successfully and your script came closest to success for me.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pixel Predator - PixelSearch Script

21 Nov 2021, 02:05

darkfear42 wrote:
20 Nov 2021, 10:51
hi hellbent, your code is very impressive and thank you so much for creating it. I have a few questions that i hope you could help with

1. I would like to always fix the position to (X: 899, Y:855, W:20, H:2) and color to 0xBBF8FE, variation 5. Please let me know if this amendment to your code is correct

Code: Select all

global HB_Button:=[],Selected_Color:="BBF8FE",Color_Edit:="0xBBF8FE",Stop:=1,X_Pos:="899",Y_Pos:="855",W_Pos:="20",H_Pos:="2",cx2:="",cy2:="",cx:="",cy:="",Commands:="",Variation:=5,Start_Key :="Numpad1",Stop_Key:="Numpad2",RTimes:=1,CMove:=1,CTimes:=1,XOff:=10,YOff:=10,TypeC:="Left",Send_Stuff:="",M_Delay:=30,Key_Delay:=30,Delay:=500
I don't remember why I had done it this way, but "X_Pos" etc are for the display edits and "cx" etc holds the actual values used.

so

Code: Select all

global HB_Button:=[],Selected_Color:="BBF8FE",Color_Edit:="0xBBF8FE",Stop:=1,X_Pos:=899,Y_Pos:=855,W_Pos:=20,H_Pos:=2,cx2:=X_Pos + W_Pos,cy2:= Y_Pos + H_Pos ,cx:=X_Pos,cy:=Y_Pos,Variation:=5,RTimes:=1,CMove:=1,CTimes:=1,XOff:=10,YOff:=10,TypeC:="Left",Send_Stuff:="",M_Delay:=30,Key_Delay:=30,Delay:=500
Then update the edits value

Code: Select all

Gui,1:Add,Edit, x175 y100 w40 h22 Center ReadOnly vX_Pos,% X_Pos
Gui,1:Add,Edit, x245 y100 w40 h22 Center ReadOnly vY_Pos,% Y_Pos
Gui,1:Add,Edit, x315 y100 w40 h22 Center ReadOnly vW_Pos,% W_Pos
Gui,1:Add,Edit, x385 y100 w40 h22 Center ReadOnly vH_Pos,% H_Pos
2. I want it to press D after detecting the color so I selected the T version. I would like to add a rand sleep of 450ms to 580ms after detecting the color, and a fixed sleep of 2000ms after execution of keypress D before restarting the whole process. Please advise how should I amend the code so that I can make it the default every time i start pixel hunter 1) Default to text version
Make sure you have the updated (secret version) found at the bottom of the first page of the thread and then edit this line.

Code: Select all

;======================================================================
;   Set Default Command line.   
;   --------------------------
global Commands := ComLDel "0" ComLDel "0" ComLDel "1" ComLDel "0" ComLDel "0" ComLDel "Left" ComLDel "30" ComLDel "30" ComLDel "500" ComLDel

;======================================================================
The thing you want to send goes at the end after the last "ComLDel"
2) Detect color then Rand sleep of 450 to 580ms, 3) keypress D, 4) fixed sleep 2000ms
This requires editing the logic

Here is some of it (see random)

Code: Select all

			if(Send_Stuff){
				if(Substr(Send_Stuff,1,5)="[RUN]"){
					RunStuff()
					Stop_Search()
					return
				}else if(Substr(Send_Stuff,1,7)="[close]"){
					CloseStuff()
					Stop_Search()
					return
				}else if(Substr(Send_Stuff,1,7)="[Sound]"){
					SoundStuff()
					if(RTimes=0){
						Stop_Search() 
						return
					}
					continue
				}
				random, out, 400, 800
				Sleep, % Out
				Send_Function(Send_Stuff)
			}
			if(RTimes=0){
				Stop_Search() 
				return
			}
			Sleep,% Delay
Delay is your 2k ms
darkfear42
Posts: 3
Joined: 20 Nov 2021, 10:33

Re: Pixel Predator - PixelSearch Script

21 Nov 2021, 04:42

Thanks for your reply hellbent. I got setting the defaults quite easily, but the logic editting is way beyond my understanding (I only started AHK yesterday sorry). I've updated the script to the secret version and made sure the global commands are as you mentioned. I am not even sure which part of the code should i amend haha.. hope you can enlighten which part of the script

Code: Select all

;   Set Default Command line.   
;   --------------------------
global Commands := ComLDel "0" ComLDel "0" ComLDel "1" ComLDel "0" ComLDel "0" ComLDel "Left" ComLDel "30" ComLDel "30" ComLDel "500" ComLDel 
			if(Send_Stuff){
				if(Substr(Send_Stuff,1,5)="[RUN]"){
					RunStuff()
					Stop_Search()
					return
				}else if(Substr(Send_Stuff,1,7)="[close]"){
					CloseStuff()
					Stop_Search()
					return
				}else if(Substr(Send_Stuff,1,7)="[Sound]"){
					SoundStuff()
					if(RTimes=0){
						Stop_Search() 
						return
					}
					continue
				}
				random, out, 450, 580
				Sleep, % Out
				Send_Function(Send_Stuff)
			}
			if(RTimes=0){
				Stop_Search() 
				return
			}
			Sleep 2000
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Pixel Predator - PixelSearch Script

21 Nov 2021, 05:32

darkfear42 wrote:
21 Nov 2021, 04:42
Thanks for your reply hellbent. I got setting the defaults quite easily, but the logic editting is way beyond my understanding (I only started AHK yesterday sorry). I've updated the script to the secret version and made sure the global commands are as you mentioned. I am not even sure which part of the code should i amend haha.. hope you can enlighten which part of the script

Change [Edit] this to be what you want the default command line to be.

You said that you wanted to add text so you need to edit the values (you can press "T" and just copy the values)
and at the end (after the last "ComLDel" ) add what you want to type i.e ( {Enter 3}Hello World{Enter 2} )

Code: Select all

;   Set Default Command line.   
;   --------------------------
global Commands := ComLDel "0" ComLDel "0" ComLDel "1" ComLDel "0" ComLDel "0" ComLDel "Left" ComLDel "30" ComLDel "30" ComLDel "500" ComLDel 
			
but the logic editting is way beyond my understanding
Find this code in the script

Code: Select all

			if(Send_Stuff){
				if(Substr(Send_Stuff,1,5)="[RUN]"){
					RunStuff()
					Stop_Search()
					return
				}else if(Substr(Send_Stuff,1,7)="[close]"){
					CloseStuff()
					Stop_Search()
					return
				}else if(Substr(Send_Stuff,1,7)="[Sound]"){
					SoundStuff()
					if(RTimes=0){
						Stop_Search() 
						return
					}
					continue
				}
				Send_Function(Send_Stuff)
			}
			if(RTimes=0){
				Stop_Search() 
				return
			}
			Sleep,% Delay
and replace it with

Code: Select all

			if(Send_Stuff){
				if(Substr(Send_Stuff,1,5)="[RUN]"){
					RunStuff()
					Stop_Search()
					return
				}else if(Substr(Send_Stuff,1,7)="[close]"){
					CloseStuff()
					Stop_Search()
					return
				}else if(Substr(Send_Stuff,1,7)="[Sound]"){
					SoundStuff()
					if(RTimes=0){
						Stop_Search() 
						return
					}
					continue
				}
				random, out, 400, 800  ;<<<<<<< Your random values
				Sleep, % Out   ;<<<<<<<Sleeping the random value
				Send_Function(Send_Stuff)
			}
			if(RTimes=0){
				Stop_Search() 
				return
			}
			Sleep,% Delay  ; <<<<<<<< Loop delay [  *9*  in the command line  ( Press the "?" ) ]
HTH

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: jacek678, sanmaodo and 75 guests