Pixel Predator - PixelSearch Script

Post your working scripts, libraries and tools
User avatar
SpeedMaster
Posts: 369
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: 1005
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: 369
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. You provided a new version without even warning that you had disabled the EXIT and changed the STOP shortcut. When I saw the new version with a new interface I wanted to try it, I didn't need to look at the keyboard shortcuts since I already knew them !!
It was when I wanted to stop and leave the script that I found myself in this awful situation. ESC and Ctrl + Esc was no longer working :shock: and there was no way to use the mouse either (that was stuck on the target pixel)
Fortunately I had a killer script :D but I don't think this should be the case for other users who are still using the old version they will probably find themselves in the same position as me when they try the new version. I just wanted to warn you about that. :!:
Hellbent wrote:
27 Oct 2019, 04:21
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)...
I am aware that using AHK is risky and you can never change that, but what you can do is minimize the risks, so I think that any potentially dangerous script should have at least a common way to exit it, the ESC key or a function key (F1 to F12) or a combination of Ctrl/ALT/Win with the ESC/Q/X/W keys. The user is free to disable it if he wants at it's own risk.
:arrow: if you know that your script is potentially dangerous why then disable the shortcut to EXIT the program in the new version ?
Speedmaster wrote: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.
Hellbent wrote:
27 Oct 2019, 04:21
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.
You didn't make a game here, but a TOOL: the chances are high that someone will use it in their workplace and that's where the problems start. Office workers use the numpad a lot and if a co-worker notices that his numpad keyboard is not more working properly, he will call his IT-department and, believe me, these guys, even if they are computer engineers and graduates, are not always aware of AHK or AHK-friendly , they will report to anti-virus companies that someone has created a malicious script with AHK called "Pixel Predator" (only the name can scare a manager).
:arrow: So, If you like to use ahk and make a useful tool why then disabling important keys of the numpad by default ?

Maybe you are not aware of the forum rule.
https://autohotkey.com/board/topic/110605-no-pranks-or-any-other-potentially-harmful-stuff-is-allowed/
Hellbent wrote:
27 Oct 2019, 04:21
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.
that's what I proposed in the previous post :thumbup:
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,
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: 1005
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: 1005
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: 1005
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: 1
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

Return to “Scripts and Functions”

Who is online

Users browsing this forum: coolbranded, kczx3, robodesign and 131 guests